Crontab doesn't execute self-written script
Hi everyone,
I've written a script that generates a system report. I want to run the script (for testing) every minute, however, crontab doesn't execute it. But the "ntpdate" command and the "service restart" command ARE working fine... I've set the PATH variable and I'm using the full path name of the script. When I execute the same command in the shell it works just fine... Any advice? Code:
SHELL=/bin/bash |
Make sure the script is executable. ( chmod a+x <script name> )
|
what user are you running cron as, and what are the permissions of the script?
|
About a year ago, I spent a good deal of time trying to work out why one cron event was not executed. In the end, it turned out to be the fact that the crontab did not have a blank line at the end of the file (and the event that was no executing was the last event in crontab)! I'm not sure if that problem exists in all cron implementations, but it was a very annoying error. It was only when I looked at a crontab from another machine running the same distro that I spotted the difference....
Paul. |
There was a problem in some of the older version of crontab on Solaris, where a blank last line would cause issues .. ;)
On Linux and *nix systems generally I've found that removing any blank lines at the bottom usually works .. I guess you just have to try these things; they come with experience ie the books don't usually mention them... |
Quote:
|
Quote:
When I run the script at the shell without using sudo, it does work fine... (using sudo of course as well ;)) Code:
-rwxr-xr-x 1 root root 880 2012-05-17 18:18 systemcaptureCSV* |
I would try to catch the output. (I mean next to 2>> you may need >>/home/laurent/logs/stats_HTML.stdout).
Also try to set -xv at the beginning of your script and echo some text to see it it was started. |
Quote:
|
this usually caused by the special environment set by cron. That's why catching the output of those tasks may give you helpful information.
Also you can try to put an echo "hello world" > /tmp/cronjoblogfile into your scripts to see if they started. You can check the mailbox of the user, sometimes cron sends mails. |
Quote:
This is how my cron looks now: Code:
SHELL=/bin/bash Code:
-rwxrwxrwx 1 laurent laurent 180 2012-05-17 19:30 stats.csv* Code:
#!/bin/bash Code:
#!/bin/bash BUT BUT!! The error files are NOT empty! Let's have a look at them: Code:
REPORT_FILE="$HOME/stats.csv" |
yes, probably the report file is taken from root's home instead of yours. So use
REPORT_FILE="~laurent/stats.csv" or absoluthe path. You can look for another occurrences as well. _________________________________ Happy with solution ... mark as SOLVED If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post. |
Quote:
|
All times are GMT -5. The time now is 03:36 PM. |