LinuxQuestions.org
Register a domain and help support LQ
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 10-21-2013, 08:47 AM   #1
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Rep: Reputation: 46
convert works from CLI, but doesn't work when cron'd in a .sh


Hi guys. I tried to make a cron job that just runs some convert commands then moves the files somewhere for me. When i run the commands copied and pasted from my cron'd .sh they work. But they never seem to work when the cron job runs automatically.
If I do a ./scriptname.sh it works though which confuses me.

Any ideas what I should check?
 
Old 10-21-2013, 08:52 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
that was discussed several times, see similar threads at the bottom.
cron has its own special environment, you need to take care about it: use full path, catch stdout and stderr.
 
Old 10-21-2013, 09:08 AM   #3
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Original Poster
Rep: Reputation: 46
I did read some of them already. I have the full path in there for my commands. the script is executable. My guess is it's something to do with convert or the fact that convert is in usr/local/bin, where all my other programs I have cron'd are in /usr/bin, but convert has -rwxr-xr-x which is what other things I have cron'd have. Maybe I have to have usr/local/bin added somewhere i'm unaware of?

When I run the script from the command line though, it doesn't give any errors as to why it doesn't work.
 
Old 10-21-2013, 11:09 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
please show us your crontab entry and the script if possible
 
Old 10-21-2013, 11:23 AM   #5
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Original Poster
Rep: Reputation: 46
Here's the entry

05 2 * * 1-6 /scripts/optimizer.sh

Here's the script, I took out the lines that do the mv's and other stuff that is working, as those all work, its just these two lines for convert that don't.


#!/bin/bash
#set -xvvv #debugger

/usr/local/bin/convert -scale 145 -depth 8 /PDFs/*.pdf /PDFs/145_`date +%m-%d-%Y`.png
/usr/local/bin/convert -scale 400 -depth 8 /PDFs/*.pdf /PDFs/400_`date +%m-%d-%Y`.png

exit
 
Old 10-21-2013, 11:24 AM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
99% of the time when a script works on the command line but doesn't work in cron, it's because of the environment difference (namely the PATH) - ignoring of course those cases when the cron isn't even running.

Try sticking a "> ~/convert_cron.log 2>&1" onto the end of your cron command, then check that file after it runs for clues.

If the file doesn't exist, then make sure cron is running, and make sure you have a blank line as the last line in your crontab (sometimes cron won't run the last command in the crontab if there's not a blank line after it).
 
1 members found this post helpful.
Old 10-21-2013, 11:29 AM   #7
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Original Poster
Rep: Reputation: 46
Thanks, I'll give it a shot. I know the cron runs because it does everything except those convert commands. a totally uneducated guess is that it's something about the /usr/local/bin path to convert it doesn't like but i'm just guessing based off my other cron jobs using commands in /usr/bin ok.
 
Old 10-21-2013, 11:51 AM   #8
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Original Poster
Rep: Reputation: 46
Very interesting, in that log file it created, I see a bunch of errors from convert now!
 
Old 10-21-2013, 12:32 PM   #9
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
Quote:
Originally Posted by rjo98 View Post
Very interesting, in that log file it created, I see a bunch of errors from convert now!
and thus the reason for using logs in every bash script you create until it is mastered, and even then it does not hurt to leave for future alterations to the script.
 
1 members found this post helpful.
Old 10-21-2013, 01:14 PM   #10
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Original Poster
Rep: Reputation: 46
yeah, I like that. I never really created any on my own, just inherited some "elaborate" setup of scripts haha. I think i'm good now.
 
Old 10-21-2013, 03:56 PM   #11
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
ive only written a few basic bash scripts, but when i was learning one of the first things i picked up on was to send as much data to a log file as possible for troubleshooting. it really helped over time to refine down the errors and strange behaviors of many of my earlier scripts.
 
1 members found this post helpful.
Old 10-21-2013, 03:58 PM   #12
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Original Poster
Rep: Reputation: 46
That is pretty cool. I didn't even realize that that might show me something totally different than the output I was seeing when running the commands manually.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] [cron] Root cron ib centos 6.3 doesn't work/ killout Linux - Newbie 2 12-17-2012 02:26 PM
PHP Pear Mail works from CLI but not from cron jevaba Programming 5 02-28-2012 10:59 PM
[SOLVED] Shell script doesn't run on cron (otherwise it works) kalashari Linux - Software 6 02-17-2012 02:50 PM
cron job doesnt work, it works manually scofiled83 Programming 8 05-30-2009 04:12 PM
Echo /devPrinting doesn't work, echo /usb/lp0 works, Testpage works, Printing doesn't Hegemon Linux - General 3 08-15-2002 02:13 PM


All times are GMT -5. The time now is 08:43 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration