LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-15-2011, 01:08 AM   #1
Euthyphro
LQ Newbie
 
Registered: Feb 2011
Posts: 3

Rep: Reputation: 0
Question Impossible cron


I'm having a ridiculous time with a cron not running, and there are no errors showing up in the cron log. I'm running centos5 i386, and the following script will run absolutely perfeclty when running from command, however, in cron it does not work. I've read on many forum posts that sometimes you have to set the PATH since cron does not see the same directory listing as a user, however, I do not think that is the case here since my other cron script with the same directory structure works fine.

I'm running the following shell script (seen as generate in cron below):

Code:
#!/bin/bash
set -e
mm=/home/elmcraft/maps/c10t
time=$(date +"%Y-%m-%d-%H%M-")
world=/home/elmcraft/ramdisk/elmador/world/

$mm -w $world -m 8 -n -L -500,500,-500,500 -q --ttf-color '0,255,0,0' --show-players -o /home/elmcraft/public_html/maps/$time'-night.png'
$mm -w $world -m 8 -L -500,500,-500,500 -q -o /home/elmcraft/public_html/maps/$time'-day.png'

convert -resize 3% /home/elmcraft/public_html/maps/$time-night.png /home/elmcraft/public_html/maps/thumbnails/thumbnail-$time-night.png
convert -resize 3% /home/elmcraft/public_html/maps/$time-day.png /home/elmcraft/public_html/maps/thumbnails/thumbnail-$time-day.png
fairly simple, here is my cron:

Code:
SHELL=/bin/bash
*/30 * * * * /home/elmcraft/backups/elmador_backup.sh
* * * * * /home/elmcraft/maps/generate
You will notice the .sh is missing on generate because I have read a few other threads where people said sometimes cron doesn't like the .sh extension when executing a script. So I've tried using PATH, tried removing and using the .sh extension, but still no luck. elmador_backup.sh works perfectly fine, however, map generate does not.

Does anyone have any suggestions on why this may not be running? I want it to run every minute.
 
Old 02-15-2011, 02:06 AM   #2
ozanbaba
Member
 
Registered: May 2003
Location: İzmir
Distribution: Slackware64 15.0 Multilib
Posts: 778

Rep: Reputation: 135Reputation: 135
try it with full path.
 
Old 02-15-2011, 08:55 AM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by ozanbaba View Post
try it with full path.
Do you mean, for example "/usr/bin/convert" instead of "convert"?
 
Old 02-15-2011, 08:58 AM   #4
ozanbaba
Member
 
Registered: May 2003
Location: İzmir
Distribution: Slackware64 15.0 Multilib
Posts: 778

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by MTK358 View Post
Do you mean, for example "/usr/bin/convert" instead of "convert"?
Yes, I did. Using full path is good thing to do in crontab or any script gets run by cron.
 
Old 02-15-2011, 09:57 AM   #5
Euthyphro
LQ Newbie
 
Registered: Feb 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Tried using /usr/bin/convert but still no luck I also tried removing the lines with convert altogether and it still did not run in cron.
 
Old 02-15-2011, 10:17 AM   #6
ozanbaba
Member
 
Registered: May 2003
Location: İzmir
Distribution: Slackware64 15.0 Multilib
Posts: 778

Rep: Reputation: 135Reputation: 135
how about date? /usr/bin/date
 
Old 02-15-2011, 11:04 AM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
"set -e" means "exit immediately if a command exits with a non-zero status". Try commenting out that line or replace temporarily for debugging purposes with "set -vx"?
 
Old 02-15-2011, 02:10 PM   #8
Euthyphro
LQ Newbie
 
Registered: Feb 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by unSpawn View Post
"set -e" means "exit immediately if a command exits with a non-zero status". Try commenting out that line or replace temporarily for debugging purposes with "set -vx"?
That was it, it worked after changing from set -e to set -vx.

Just out of curiosity, is there another place where cron errors would show? I've been looking in /var/log/cron but it doesn't seem to show any error messages, just simply which user has run a cron. I've browsed through many threads and everyone else says that /var/log is the place to be.
 
Old 02-15-2011, 04:08 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Then you can comment out the "set -vx" line and spare yourself getting emailed any output if none is required. By default cron emails the user any output it the "MAILTO" variable is set.
 
Old 02-15-2011, 05:09 PM   #10
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Do you have an empty line at the end of the cron file?
Is this your own cron, or is it /etc/crontab? In the latter case you have to specify a user.

Not running files with .sh extension is nonsense. But better use full paths, and call the program to execute the script explicitely, eq. /bin/bash /path/to/your/script.sh The script file does not have to be executable.

With intervals so short I usually prefer a continuous loop in my script:
Code:
while [ 1 ] 
do
   your stuff here
   sleep 60
done
jlinkels
 
Old 02-17-2011, 02:15 PM   #11
Deviathan
Member
 
Registered: Dec 2005
Posts: 52

Rep: Reputation: 18
Is it showing that it ran in cron at all? You could try appending something like
"> /tmp/generate.log 2>&1"
to your cron entry to catch any errors or messages being output. Also, what others said, always use full path and file names.
 
Old 02-18-2011, 12:23 AM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Also, cron will attempt to email the user (or root ) if it has an error.
 
Old 02-18-2011, 02:40 AM   #13
ozanbaba
Member
 
Registered: May 2003
Location: İzmir
Distribution: Slackware64 15.0 Multilib
Posts: 778

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by chrism01 View Post
Also, cron will attempt to email the user (or root ) if it has an error.
That depends on the version a little bit. dillon's lightweight cron daemon tries to email the use output of the command run.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cron.hourly cron.weekly cron.monthly and 0anacron. Are they necessary? glore2002 Debian 2 09-30-2009 08:57 PM
Cron appears to be messed up (E: cron: subprocess post-installation script returned e bujutsukai Linux - Newbie 1 07-24-2008 03:39 AM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 01:57 AM
Can any one plz explain why/what for cron.d, cron.daily, cron.weekly etc are there. mavinashbabu Linux - Newbie 4 09-21-2006 01:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

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