cron stops in the middle of the script
I've written a script that I'd like to run at certain times, and I'm trying to use cron to do this. However, I've been only partially succesful in getting the script to run properly under cron.
For some reason, it seems that cron is only allowing my script to run for a second or two. To test this out, I wrote at test script that instructs my computer simply to play some mp3 files using mplayer. Cron does, indeed, execute this script, but mplayer will only play for about a second, and then it stops.
Here's the line that I'm using in the /etc/crontab file:
18 16 * * * root sh /home/dave/tmp/testscript.sh &
I tried it with and without the 'sh' and with and without the '&'. All with the same one-second result.
Of course, my testscript.sh runs fine manually from the command line.
/var/log/cron/errors doesn't show any errors from my one-second attempts. /var/log/cron/warnings is empty. /var/log/cron/info seems to show all OK too.
Thanks in advance.
The problem seems to be within the script. Could you post the script?
The test script I was using was just:
This was just to see what was to see if the script would run using cron, which it did, but I only got sound for a second or two.
The script works fine when I run ./testscript.sh
The *real* script that I want to use is the following.
What does the "root" command do? I use Fedora and haven't come across that one.
I'm pretty sure it just specifies which user is supposed to run the command, but I'm not sure. In any case, I've tried it without "root" or any other user name and I get the same problem.
OK. I fixed the problem, so hopefully this should help someone else out someday.
I fixed the problem by changing the crontab file to:
6 18 * * * at now < /home/dave/tmp/testscript.sh
The "at now" is the key. I don't know why cron wouldn't run the script directly, but using the at command gets around the problem.
I take that back... I did *not* fix the problem as I indicated in my last post. I just did a fix that happened to work with my testscript. It did not actually end up working on other scripts, however.
Luckily, I did figure out what the ultimate problem was (at least I'm 90 percent sure I did) and so hopefull this will be useful to someone. Maybe I'll put it somewhere in the WIKI. What was happening was that when I went the script ran from cron it would have output that it would want to send somewhere. I had a line in my crontab file...
...that was supposed to "e-mail" me output. Apparently this wasn't working, so it would try to submit output, that output couldn't go anywhere and so the process would quit.
What I did to fix this was something suggested at this website:
>> /dev/null 2>&1
...at the end of each crontab listing. According to the above website, "The >> /dev/null 2>&1 part means to send any standard output to /dev/null (the linux trash can) and to redirect standard error (2) to the same place as the standard output (1). Basically it runs the command without any output to a terminal etc."
So now my scripts are running as they should.
|All times are GMT -5. The time now is 08:12 PM.|