LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-07-2015, 09:03 AM   #1
deepGC
LQ Newbie
 
Registered: May 2015
Posts: 21

Rep: Reputation: Disabled
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?
 
Old 06-07-2015, 09:21 AM   #2
JeremyBoden
Senior Member
 
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,947

Rep: Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511
Try
Code:
echo "$f" >> ~/log.log
The log will be in your home directory.
 
Old 06-07-2015, 09:46 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
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.
 
Old 06-07-2015, 10:13 AM   #4
deepGC
LQ Newbie
 
Registered: May 2015
Posts: 21

Original Poster
Rep: Reputation: Disabled
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

Last edited by deepGC; 06-07-2015 at 10:20 AM.
 
Old 06-07-2015, 10:24 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
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 ".".
 
Old 06-07-2015, 10:31 AM   #6
deepGC
LQ Newbie
 
Registered: May 2015
Posts: 21

Original Poster
Rep: Reputation: Disabled
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
 
Old 06-07-2015, 10:39 AM   #7
deepGC
LQ Newbie
 
Registered: May 2015
Posts: 21

Original Poster
Rep: Reputation: Disabled
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?
 
Old 06-07-2015, 02:38 PM   #8
deepGC
LQ Newbie
 
Registered: May 2015
Posts: 21

Original Poster
Rep: Reputation: Disabled
Solved,

I copied the environment variables from the command line environment, then assigned them manually in the crontab script
 
Old 06-07-2015, 03:06 PM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
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.

Last edited by michaelk; 06-07-2015 at 03:21 PM.
 
Old 06-07-2015, 03:28 PM   #10
deepGC
LQ Newbie
 
Registered: May 2015
Posts: 21

Original Poster
Rep: Reputation: Disabled
It's Centos 6 here
 
  


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
Crontab script ikn3 Linux - Newbie 2 03-12-2013 10:22 PM
Script crontab jedi777 Linux - Newbie 2 01-27-2011 12:52 AM
[SOLVED] Crontab Script Not Running th1bill Ubuntu 4 12-10-2010 03:49 PM
Runs Multiple shell script inside a main script using crontab srimal Linux - Newbie 4 10-22-2009 06:19 PM
crontab ruins my script riotxix Programming 3 05-14-2008 08:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:25 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