Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
52
rated 0 times [  52] [ 0]  / answers: 1 / hits: 149576  / 1 Year ago, fri, february 10, 2023, 8:19:29

  1. How can I see crontab tasks which are in progress?

  2. 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 ???


More From » cron

 Answers
4

Firstly, use only one command per line in crontab. Change this crontab line:



00 10 * * * /usr/bin/wget LINK ; shutdown -h now


so it looks like:



00 10 * * * /path/to/my/crontab/script1.sh


and create /path/to/my/crontab/script1.sh with this content:



#!/bin/bash
/usr/bin/wget LINK
shutdown -h now


Of course, don't forget to give it execution permission:



chmod +x /path/to/my/crontab/script1.sh





Secondly, you can see running crontab tasks, in a useful and readable format, in the output of:



ps -o pid,sess,cmd afx | egrep -A20 "( |/)cron( -f)?$"


They will appear in the first lines, something like this:



1108  1108 cron
4288 1108 _ CRON
4289 4289 _ /bin/sh -c /path/to/my/crontab/script1.sh
4290 4289 _ /bin/bash /path/to/my/crontab/script1.sh
4295 4289 _ /usr/bin/wget LINK


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:



pkill -s 4289

[#30573] Friday, February 10, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mouedi

Total Points: 420
Total Questions: 109
Total Answers: 116

Location: Philippines
Member since Wed, Aug 19, 2020
4 Years ago
;