-   Linux - Newbie (
-   -   cron stops in the middle of the script (

djzanni 05-20-2005 06:01 PM

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/ &

I tried it with and without the 'sh' and with and without the '&'. All with the same one-second result.

Of course, my 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.


jailbait 05-22-2005 11:30 AM


The problem seems to be within the script. Could you post the script?

Steve Stites

djzanni 05-22-2005 11:58 AM

The test script I was using was just:

mplayer /home/dave/music/*mp3

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 ./

The *real* script that I want to use is the following.


# recorded from WETA live stream. WETA broadcasts the newshour at 7PM ET.
at now + 60 minutes <
mplayer -playlist $URL -dumpstream -dumpfile $FILENAME -vc dummy -vo null;
mplayer $FILENAME -ao pcm -aofile $FILENAME.wav -vc dummy -vo null
lame $FILENAME.wav /home/dave/iPodderData/downloads/$FILENAME-`date +%F`.mp3
rm -f $FILENAME.wav


eddiebaby1023 05-23-2005 06:48 PM

What does the "root" command do? I use Fedora and haven't come across that one.

djzanni 05-23-2005 10:46 PM

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.

Thanks tho,

djzanni 05-27-2005 09:23 AM

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/

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.


djzanni 06-02-2005 06:29 PM

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:

I put...

>> /dev/null 2>&1 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 02:25 AM.