LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Crontab strats 2 processes, calling 1 script (https://www.linuxquestions.org/questions/linux-newbie-8/crontab-strats-2-processes-calling-1-script-4175512469/)

shridhar22 07-27-2014 11:48 PM

Crontab strats 2 processes, calling 1 script
 
My crontab had the command:
Quote:

50 08 * * 1-5 /home/MY_SCRIPT.py /home/arguments 2> /dev/null

59 23 * * 1-5 killall MY_SCRIPT.py
Which worked perfectly fine, but when I used to do
Code:

ps aux | grep SCRIPT
it showed

Quote:

myuser 13898 0.0 0.0 4444 648 ? Ss 08:50 0:00 /bin/sh -c /home/MY_SCRIPT.py /home/arguments 2> /dev/null

myuser 13900 0.0 0.0 25268 7384 ? S 08:50 0:00 /usr/bin/python /home/MY_SCRIPT.py /home/arguments
  1. Why are 2 processes been shown
And the killall command also used to work fine.

I made a change to my script and in order to get the new behaviour, I had to kill the currently running scripts and I used
Code:

kill 13898 13900
After that I used the same command (as in crontab)
Code:

/home/MY_SCRIPT.py /home/arguments 2> /dev/null
  1. But now after restrating the script, it showed only 1 process (which makes sense)

Everything looks good till here, but this time the killall MY_SCRIPT in the cronjob didnt work, it said could not find pid. And the script kept on running until I had to manually kill it.

Need to find out the reason for this behaviour:
  1. Why 2 processes from cronjob
  2. Is there something wrong the way I restrated the script
  3. How do I make sure that next time I restart the script, the cron should kill it for sure

rknichols 07-28-2014 08:55 AM

The cron daemon needs to invoke a shell to process the "2>/dev/null" redirection. The only way I can think of to get rid of that shell process is to change MY_SCRIPT.py to a shell script that explicitly exec-s the python interpreter:
Code:

#!/bin/sh
exec python - "$@" <<EOF
  your
  script
  here
EOF

I think that will work, but I don't have a suitable script for testing it.


All times are GMT -5. The time now is 06:17 PM.