LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 04-09-2004, 07:07 PM   #1
kleptophobiac
Member
 
Registered: Jun 2003
Distribution: Arch
Posts: 315

Rep: Reputation: 30
script runs fine from a command line, but doesn't work from cron?


This is a reasonably simple bash script to compress any new wav files in the audio directory into MP3. I know I could have lame be the command in the if statement... but I like it like this.

Anyway, when I issue the command as root from the console, it works flawlessly. When it runs from cron, it starts and exits instantaneously. The wav is deleted, and the mp3 "encoded" in under a quarter of a second. Yeah right. No MP3 output whatsoever.

Why does it work just fine from the console, but dies from cron? Permissions for the script are 4777.

Code:
#!/bin/bash
#Archives old MP3's, and compresses new ones

#Set DATE variable to today
DATE=`date +'%m-%d-%Y'`

#Sets permissions on the audio folder
chmod -R 0777 /audio

#Checks to see if there is a new wav file. Does nothing if there is not.
if ls /audio/*.wav
then

        #Output to log file
        echo `date` " - Found WAV file, encoding..." >> /scripts/encode_output

        #Move old MP3's into an archive directory
        mv /audio/*.mp3 /audio/archive/

        #Encodes wav file into MP3
        lame -a -h -b 96 /audio/*.wav /audio/$DATE.mp3

        #Output to log file
        echo `date` " - It encoded" >> /scripts/encode_output

        #Changes file permissions
        chown root:root /audio/$DATE.mp3
        chmod 777 /audio/$DATE.mp3

        #Erases the WAV file
        rm /audio/*.wav
else
        echo `date` " - No file found, no action taken." >> /scripts/encode_output
fi
 
Old 04-09-2004, 10:31 PM   #2
jailbait
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,575

Rep: Reputation: 184Reputation: 184
"Anyway, when I issue the command as root from the console, it works flawlessly. When it runs from cron, it starts and exits instantaneously."

When you execute the script in cron are you using the full path name to the script? cron does not have much of a PATH.

What is the ownership of the command? I think that it has to be root root for cron to be able to execute it.

___________________________________
Be prepared. Create a LifeBoat CD.
http://users.rcn.com/srstites/LifeBo...home.page.html

Steve Stites
 
Old 04-09-2004, 11:27 PM   #3
kleptophobiac
Member
 
Registered: Jun 2003
Distribution: Arch
Posts: 315

Original Poster
Rep: Reputation: 30
File ownership is root, file permission in 4777.

Yes, I issue the full path. I get entries to the log file, so I know it is running.
 
Old 04-10-2004, 02:21 PM   #4
jailbait
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,575

Rep: Reputation: 184Reputation: 184
"Yes, I issue the full path. I get entries to the log file, so I know it is running."

All of the commands that you issue in the script are in /bin except lame. Where is lame? Is it in the cron PATH? You may have to give the full pathname for the lame command.

To find out what the cron PATH is you could put this command in the script:
echo $PATH >> /scripts/encode_output

___________________________________
Be prepared. Create a LifeBoat CD.
http://users.rcn.com/srstites/LifeBo...home.page.html

Steve Stites

Last edited by jailbait; 04-10-2004 at 02:23 PM.
 
Old 04-10-2004, 03:17 PM   #5
kleptophobiac
Member
 
Registered: Jun 2003
Distribution: Arch
Posts: 315

Original Poster
Rep: Reputation: 30
lame is in /bin as well.. I copied it in there.
 
Old 05-03-2004, 05:14 PM   #6
nerdstat
LQ Newbie
 
Registered: Apr 2004
Location: Brussels, Belgium
Distribution: Gentoo with 2.6.8-kernel
Posts: 15

Rep: Reputation: 0
The simplest solution is to check you PATH variable by using 'echo $PATH' in your shell and then pasting that information on the second line of your script...
Something like this:
Code:
#!/bin/bash
PATH=blablabla
#Archives old MP3's, and compresses new ones
Don't forget to fill in the variable PATH...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
cron issue, php script runs fine in browser and cli dtra Linux - Software 1 07-15-2005 06:45 AM
C++ prorgam runs OK from command line, but failed from crontab vgolden Linux - Software 2 01-21-2005 12:00 PM
cron jobs work fine when invoked from webmin but fail on schedule jillu Linux - Enterprise 3 01-20-2005 02:34 PM
Perl shell-out to script dunna work. Works on command line. Why? jlangelier Linux - Software 1 08-28-2004 03:00 AM
Command line runs back on itself SharpyWarpy Linux - General 2 11-25-2003 07:56 PM


All times are GMT -5. The time now is 02:07 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration