- How can I see crontab tasks which are in progress?
- How can I stop crontab tasks which are in progress, manually?
Is [this] question about see the current running cron processes?
Yes
To kill a process manually one way is to use pkill
I had thought about pkill/killall, but some of my commands in crontab file are respectively! it means that after finishing a command, the next one will be started! for example:
sudo crontab -e
00 10 * * * /usr/bin/wget LINK ; shutdown -h now
So, If I kill wget
, the computer will be powered off!!! -> I want to kill a cron task fully, not a part of it!
The next pkill
problem: What about scripts? (I've imported some bash scripts to crontab -e
) --> sudo pkill ???
Firstly, use only one command per line in crontab. Change this crontab line:
so it looks like:
and create
/path/to/my/crontab/script1.sh
with this content:Of course, don't forget to give it execution permission:
Secondly, you can see running crontab tasks, in a useful and readable format, in the output of:
They will appear in the first lines, something like this:
First column is PID, second is Session ID and third is the command started by cron. You can kill all the processes related to a specific cron task using the Session ID, so in the example above you should kill Session ID 4289:
To kill a process manually one way is to use
pkill
. pkill will stop all processes that have the following pattern in its name. for example to stop all wget processes use:change your cronjob like this
This should work, because the
&&
means that the second command only gets executed, when the first one was finished correctly (returning status 0 to the console/system), which shouldn't be the case (because the process got killed by the user and it should return another value then 0).