LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-28-2014, 12:48 AM   #1
shridhar22
Member
 
Registered: Mar 2012
Posts: 42

Rep: Reputation: Disabled
Question 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
 
Old 07-28-2014, 09:55 AM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,959

Rep: Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268
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.
 
  


Reply

Tags
cronjob, crontab, kill


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
calling a shell script present on another server using perl script. anandg111 Linux - Server 4 07-18-2012 01:23 AM
Calling Crontab over non interactive ssh session IgnitusBoyone Linux - General 5 06-09-2011 05:22 AM
Calling perl script and passing variable from php script hosea Programming 5 10-21-2008 09:01 AM
how to pass a variable from a called script back to the calling script steven.c.banks Linux - General 2 05-05-2008 03:00 PM
suspend running processes with crontab merlin23 Linux - Newbie 1 12-07-2004 04:09 AM


All times are GMT -5. The time now is 04:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration