LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 06: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, 09:31 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
"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, 10: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, 01:21 PM   #4
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
"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 01:23 PM.
 
Old 04-10-2004, 02: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, 04: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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

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