script runs fine from a command line, but doesn't work from cron?
Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
"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
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.