2

what happens to my script in python that does not run through crontab every minute. My script has execute permissions and then calls two other scripts in python.


This is the content of my crontab (#crontab -l):
*/1 * * * * /usr/bin/rsm/samplesMonitor.py
Thank you guys.

1
  • What are the exact permissions on your file? Commented Mar 3, 2011 at 3:15

4 Answers 4

4

Check /var/log/syslog for errors.

DIAGNOSTICS
       cron requires that each entry in a crontab end in a 
       newline character. If the last entry in a crontab is 
       missing a newline (ie, terminated by  EOF),  cron  will 
       consider the crontab (at least partially) broken. A 
       warning will be written to syslog.

Update: According to your log message, the script is running but returning an error code. Cron will email you the output, if you have a mail agent installed.

Try either:

  1. install a mail agent, such as: apt-get install exim4
  2. change your cron line to log to file, like so:

    * * * * * /usr/bin/rsm/samplesMonitor.py 2>&1 >> /tmp/script.log
    

Update 2: I re-read your question and it acurred to me that maybe you are running into python import issues. You say that your script calls two other scripts. My suggestion would be to test running your script from /. Python has a default behavior to find imports in the current working directory, so make sure your script can run from any path location.

In the crontab, you can set the starting working directory by calling your script from within another shell process. For example:

bash -c "cd THE_WORKING_DIR;/usr/bin/rsm/samplesMonitor.py"
Sign up to request clarification or add additional context in comments.

2 Comments

syslog output: Mar 3 22:48:01 carbuncle CRON[3337]: (CRON) error (grandchild #3339 failed with exit status 127) Mar 3 22:48:01 carbuncle CRON[3337]: (CRON) info (No MTA installed, discarding output) Mar 3 22:48:01 carbuncle CRON[3336]: (CRON) error (grandchild #3340 failed with exit status 127) Mar 3 22:48:01 carbuncle CRON[3336]: (CRON) info (No MTA installed, discarding output) Mar 3 22:50:01 carbuncle CRON[3356]: (tiago) CMD (root /usr/bin/./samplesMonitor.sh) Mar 3 22:50:01 carbuncle CRON[3357]: (root) CMD (root /usr/bin/samplesMonitor.py
This is desperate, the script runs fine alone (without cron) and through cron failure! This script uses threads to send files to a web repository and makes calls to a local database. Any tips? Thank you Casey and other people.
1

I believe it should be */1, not *\1.

Comments

0

It should be */1 instead of *\1 (forward slash instead of backslash). Also, make sure the path is correct; there usually are no subdirectories under /usr/bin.

2 Comments

It was a mistake in my example but I corrected it. However my script does not run
It was a mistake in my example but I corrected it. However my script does not run anyway. Now my script is in /usr/bin My crontab: */1 * * * * /usr/bin/samplesMonitor.py
0

If you want it to run every minute, just do this

* * * * * /usr/bin/rsm/samplesMonitor.py

1 Comment

Ok but every minute is an example, however my script does not run anyway. Example (every 5 minutes): */5 * * * * /usr/bin/samplesMonitor.py

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.