LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   script runs fine from a command line, but doesn't work from cron? (https://www.linuxquestions.org/questions/linux-software-2/script-runs-fine-from-a-command-line-but-doesnt-work-from-cron-168304/)

kleptophobiac 04-09-2004 06:07 PM

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


jailbait 04-09-2004 09:31 PM

"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

kleptophobiac 04-09-2004 10:27 PM

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.

jailbait 04-10-2004 01:21 PM

"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

kleptophobiac 04-10-2004 02:17 PM

lame is in /bin as well.. I copied it in there.

nerdstat 05-03-2004 04:14 PM

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


All times are GMT -5. The time now is 04:34 AM.