LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 05-20-2005, 05:01 PM   #1
djzanni
Member
 
Registered: Dec 2003
Location: Washington, DC
Distribution: Ubuntu 7.04
Posts: 73

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

Suggestions?

Thanks in advance.

~daveZ
 
Old 05-22-2005, 10:30 AM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
"Suggestions?"

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

-----------------------
Steve Stites
 
Old 05-22-2005, 10:58 AM   #3
djzanni
Member
 
Registered: Dec 2003
Location: Washington, DC
Distribution: Ubuntu 7.04
Posts: 73

Original Poster
Rep: Reputation: 15
The test script I was using was just:

#!/bin/bash
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 ./testscript.sh

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

Code:
#!/bin/bash
# recorded from WETA live stream. WETA broadcasts the newshour at 7PM ET.
URL=http://www.weta.org/fm/live_noclip.ram
FILENAME=Newshour-PBS
at now + 60 minutes < quit.sh
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
rm -f $FILENAME
Thanks.
~daveZ
 
Old 05-23-2005, 05:48 PM   #4
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
What does the "root" command do? I use Fedora and haven't come across that one.
 
Old 05-23-2005, 09:46 PM   #5
djzanni
Member
 
Registered: Dec 2003
Location: Washington, DC
Distribution: Ubuntu 7.04
Posts: 73

Original Poster
Rep: Reputation: 15
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,
~daveZ
 
Old 05-27-2005, 08:23 AM   #6
djzanni
Member
 
Registered: Dec 2003
Location: Washington, DC
Distribution: Ubuntu 7.04
Posts: 73

Original Poster
Rep: Reputation: 15
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.

~daveZ
 
Old 06-02-2005, 05:29 PM   #7
djzanni
Member
 
Registered: Dec 2003
Location: Washington, DC
Distribution: Ubuntu 7.04
Posts: 73

Original Poster
Rep: Reputation: 15
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...

MAILTO=dave

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

http://www.linuxhelp.net/guides/cron/

I put...

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

~daveZ
 
  


Reply



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
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
Installation stops in the middle of bootup (on new machine) lostinpurdy Linux - Newbie 4 10-05-2005 09:12 PM
slax stops in the middle of boot-up aquilolumen Slackware 13 08-15-2005 12:09 AM
PPPD Script problem when cron-scheduling the script andresurzagasti Linux - Networking 0 11-24-2004 02:54 PM
Why my installation stops in middle vivek007 Red Hat 3 10-31-2003 11:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:09 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
Open Source Consulting | Domain Registration