Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-07-2006, 03:07 PM   #1
LQ Newbie
Registered: Jun 2006
Posts: 3

Rep: Reputation: 0
Problem using crontab

Hi, I'm a pretty experienced programmer, but am definitely a Linux newbie... so I hope I'm categorizing this question correctly.

I've written a shell script... when I run it from the command-line, it runs fine (i.e., launches the program it is supposed to launch). However, it doesn't seem to be launching when the script is run as a cron job.

I set up the cron job by typing "crontab -e" and entering the following:
* * * * * /home/Ethan/workspace/SelfPortrait/ is as follows:


echo "testing" >> /home/Ethan/workspace/SelfPortrait/log.txt
cd /home/Ethan/workspace/SelfPortrait
/home/Ethan/workspace/SelfPortrait/SelfPortrait -auto
I've check and both the script & the executable (i.e, "SelfPortrait") have the execute permission enabled. The cron job is executing the script (which I determined from the log being outputted)... and as I mentioned, running the script from the command line is also successful.

Any ideas?

Many thanks,
Old 06-07-2006, 03:26 PM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,820
Blog Entries: 15

Rep: Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664
There are different kinds of crontabs. (See man crontab, man cron).

"crontab -e" is specifically used to edit what I think of as the "real crontab" because its the one UNIX uses.

Your syntax is wrong for the "real crontab". In that crontab you need to setup the time to run then the command to run. That's what you're doing on the last line of your cron edit but the other two lines have no impact on that last line.

To fix it just add the other two lines to your script:


echo "testing" >> /home/Ethan/workspace/SelfPortrait/log.txt
cd /home/Ethan/workspace/SelfPortrait
/home/Ethan/workspace/SelfPortrait/SelfPortrait -auto
Then just put the following line in your edit:
* * * * * /home/Ethan/workspace/SelfPortrait/

By the way the above syntax is saying run ever minute 24 hours a day so might cause you some issues with performance. You may wish to modify the "* * * * *" to a specific time or at least to a less frequent run. man crontab and man cron will let you know exactly what to set.

You can have multiple lines in the "real crontab" but they all have to have a time specification then a command specification.

Also to log commands done in cron you can simply modify the line to have the log:
* * * * * /home/Ethan/workspace/SelfPortrait/ >>/home/Ethan/workspace/SelfPortrait/log.txt 2>&1 (This is all one line)

That tells it to append output to your log.

Finally there may be other environment variables besides HOME that you need to add to the script. From command line the script inherits the user's environment. From cron it has a minimal environment that is NOT inherited from the user that made the cron entry.
Old 06-07-2006, 03:44 PM   #3
Senior Member
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,439
Blog Entries: 1

Rep: Reputation: 66
Is this SelfPortrait a graphical program ?
If so, as jlightner pointed, there is an environment variable named DISPLAY which is set in graphical desktop.
In, try to add:
export DISPLAY=:0.0
before the graphical programs starts.

If SelfPortrait is a complex application, try to replace it by a single one, like xclock, just for test purposes. So, you can make sure a graphical program can be run by your cron job.
Old 06-07-2006, 04:14 PM   #4
LQ Newbie
Registered: Jun 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for the suggestions... I bet it does have something to do with an environmental variable. I added the the Display line and substituted xclock for my app--with the result that xclock doesn't launch either.

I'll play around with adding environment variables to the script... any further thoughts would be most welcome!

Old 06-07-2006, 04:21 PM   #5
LQ Newbie
Registered: Jun 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Got it working! It was the environment variables (not sure exactly which ones, since I put a bunch in).

Thanks again!


cron, path

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
crontab problem sunnyanthony Linux - Software 1 01-07-2006 05:48 AM
Crontab Problem smus Linux - Newbie 4 12-10-2005 09:52 AM
crontab problem pdrobe Red Hat 1 02-05-2005 04:19 PM
crontab problem provo1234 Linux - General 3 01-21-2005 12:20 PM
crontab problem TomTheNewbie Slackware 1 07-09-2003 08:12 AM > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration