LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Crontab script not completing (https://www.linuxquestions.org/questions/linux-newbie-8/crontab-script-not-completing-4175544726/)

deepGC 06-07-2015 09:03 AM

Crontab script not completing
 
Hi,

I've got a small script that needs processing every 24 hours. However, it is not completing and seems to quit very early.

The very first part of the script is to loop through a set of files in a directory, and I tried to log the process by adding:

echo "$f" >> /log.log
(where $f is the file name within the loop)

But the script does not even get this far as nothing is written to that log file.

Any ideas?

JeremyBoden 06-07-2015 09:21 AM

Try
Code:

echo "$f" >> ~/log.log
The log will be in your home directory.

michaelk 06-07-2015 09:46 AM

Unless you post the script or provide some more information it will be impossible for anyone to have any ideas. Does the script run if invoked from the command line?

The usual problem is that cron has a very limited path environment so unless you include the full path the script fails.
Unless you run the script as root a regular user typically does not have permissions to write to the top i.e. /. As stated try writing the log to your home directory.

deepGC 06-07-2015 10:13 AM

The script works perfectly from command line.

Here is the script:

for f in /home/housefm/public_html/wp-content/uploads/*

do

if [[ -f $f ]]; then

# $f is not a directory

g=`basename "$f"`
cp "$f" "/home/housefm/radio_server/uploaded_mixes_original/$g"
mv "$f" "/home/housefm/radio_server/processmixes/$g"
g="/home/housefm/radio_server/processmixes/"`basename "$f"`

Script works until this point
./processmix "$g"

fi

done



--> Contents of ./home/housefm/radio_server/processmixes/processmix:

echo $1 >> /log.log
echo $1 >> ~/log.log

sox "$1" "${1.mp3}"_.mp3

Other stuff....


None of the commands in the second script - processmix - are being carried out

michaelk 06-07-2015 10:24 AM

Quote:

./home/housefm/radio_server/processmixes/processmix "$g"
The . in the above command equates to current working directory which would not be the same if running as cron vs your regular user. Since the above looks like the full path just remove the ".".

deepGC 06-07-2015 10:31 AM

I've just worked out the problem:

sox formats: no handler for file extension `mp3'

For some reason, sox will not handle mp3 extension when the script is operated from crontab, although it runs fine from command line

deepGC 06-07-2015 10:39 AM

Well, I've worked out the problem, but still can't get it working.

For some reason, sox is behaving differently from crontab as to when it's run from command line. Sox does not natively come with mp3 support and needs to be added later. Crontab isn't get the same sox environment as what it would do from command line?

Any ideas on how I can get round this, or at least diagnose it further?

deepGC 06-07-2015 02:38 PM

Solved,

I copied the environment variables from the command line environment, then assigned them manually in the crontab script

michaelk 06-07-2015 03:06 PM

Great, you can mark the thread as solved via the thread tools menu at the top of the page.

I got side tracked and had to add mp3 support...

Edit: No problem with Debian 7 so looks like something that maybe specific to your distribution.

deepGC 06-07-2015 03:28 PM

It's Centos 6 here


All times are GMT -5. The time now is 11:19 AM.