Crontab not working

Posted on 2009-02-13
Medium Priority
Last Modified: 2012-05-06
I have a script which runs fine from fhe command line

when I insert it into the crontab of zx_user:

10,25,40,55 * * * * /home/zx_user/MMTVCentre/restartbrowser.sh

it supposed to run every 15 minutes, but it does not.

how can I find out why it is not running?

On a different computer I used to get /var/spool/mail/ messages... but not on this pc... where can I see why the crontabl is not running the script?

Many thanks
Question by:zeraxis_ee
  • 5
  • 3
  • 3
  • +2
LVL 29

Expert Comment

ID: 23632785
Every 15  minutes should be like this

0,15,30,45 * * * * /home/zx_user/MMTVCentre/restartbrowser.sh


did you make it executable by using chmod +x restartbrowser.sh
LVL 14

Expert Comment

by:Deepak Kosaraju
ID: 23632854
Try this which works......
*/15 * * * * /bin/sh /home/zx_user/MMTVCentre/restartbrowser.sh
LVL 40

Expert Comment

ID: 23632930
scripts to run as crontab jobs should:

- have required env variables set in the script since cron will not read user's profile file
- should refer to files and directories with full path names
- stdin , stdout, and  stderr should be redirected properly

output / errors from crontab jobs are send to user's mail box, check your mail box

cron log is under /var/log/cron
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 23

Expert Comment

by:Maciej S
ID: 23632952
Make sure, that you have proper paths set in your script.
Check every binary, which you are using in this script and provide full path to them, or define appropriate PATH variable (which will contain all necessary paths) in the beginning of your script.

Author Comment

ID: 23633886
ok I traced down the problem, but don't know how to solve it...

If I log in as root the following script will work from the command line and crontab
DATE_NOW=`date +%s`
DATE_FROM_FILE=`date -d "\`cat /home/zx_user/MMTVCentre/lastplaylist\`" +%s`
if [ ${DATE_DIFF} -gt 1200 ]; then
   export DISPLAY=":0.0"
   killall firefox
   firefox http://localhost:8080/MMTVCentre/

If I log in as zx_user and run the same script from the command line I get the error
No protocol specified
Error: cannot open display: :0.0

If I get rid of the export DISPLAY=":0.0" it will run from the command line but not the crontab

I can see messages for root from the crontab, but not for zx_user

Can anyone help?
LVL 29

Assisted Solution

fosiul01 earned 800 total points
ID: 23634025

1 If I log in as root the following script will work from the command line and crontab  

so root can execute this from command line and  crontab

does this user has ability to execute those command such as

 export DISPLAY=":0.0"
   killall firefox
   firefox http://localhost:8080/MMTVCentre/

Author Comment

ID: 23634236
zx_user can killall and open firefox

if I type in from the commandline export export DISPLAY=":0.0" it executes (at least it doesn't complain)
and if I try to open the browser from the commandline immediately after I get the error
No protocol specified
Error: cannot open display: :0.0
LVL 29

Expert Comment

ID: 23634633
to create successfull crontab , it wil have to execute properly

I dont know what this export DISPLAY=":0.0" is

but as a root i guess if you run this
export DISPLAY=":0.0" and then
try to open browsers, you can do without any problem is not it ??

if yes, then you need to assoociated the user with that command ..

how exactly this user got permision on this pc ?? is he super user ??
LVL 23

Expert Comment

by:Maciej S
ID: 23635971
As I wrote earlier - provide full path to all binaries used in your script.
So, write /bin/date (or /usr/bin/date - check where you have this binary) instead of just date. The same with killall (/bin/killall or /usr/bin/killall), and finally - firefox - /usr/bin/firefox or /usr/local/bin/firefox.

When you correct this, you may also remove that export DISPLAY... line, and instead, run your firefox like this:
DISPLAY=:0.0 /path/to/firefox http://localhost:8080/MMTVCentre/

If you don't want to write full paths, you may define PATH variable in the beginning of your script.
Check where are date, killall and firefox binaries. I assume, that you have /usr/bin/date, /usr/bin/killall and /usr/local/bin/firefox. If so, add following line above your DATE_NOW=`date +%s` line:

Author Comment

ID: 23669038
OK... I have set all the full paths... still the same error to do with the display
The crontab is running, because I changed the order of the script, and the killall works but not the DISPLAY bit.

The crontab is insalled under the USER... I switched over to root, and realised that the browser was opening, as the crontab for the USER must have been executing, as both USER and root where loggod on, except I was seeing the desktop of root.

How would I find out what the DISPLAY for the user is?

And give access if none exists.

I typed xauth list, but this seem to change every time.

I don't really understand about this DISPLAY... can anyone explain?

Author Comment

ID: 23669434
OK.. after a long search I found that if I run
xhost +local:     when the computer boots, its fine.

On some machine anyway, where the      xauth list   command returns localhost/unix
On one of the machines it returns localhost.localdomain and here it does not seem to work

LVL 23

Accepted Solution

Maciej S earned 1200 total points
ID: 23669449
DISPLAY is variable, which points you (your applications) to proper Xserver. It has format: address:Y.Z
If 'address' part is omitted, it means, that it is localhost. Y is your Xserver instance (if you have just one Xserver running, it should be 0. Z is screen number on Y's Xserver's instance.
It should be enough to set "DISPLAY=:0".
Do you have just one xserver or more? Login, and run: "echo $DISPLAY" (without "" of course) - is it ":0.0", or maybe ":1.0"? If it is 1 instead of 0, change your script accordingly.
Try running (as user who is logged in and has running X server): "xhost +localhost" (or just "xhost +" but it may be considered as security issue). After this, check if script runs correctly from crontab.
If it is, add this "xhost +localhost" command into ~/.xinitrc or some other file read during Xserver starts.

Author Comment

ID: 23679086
echo $DISPLAY for root is :0.0
and for the user is: :20.0
Why 20? Anyway, setting DISPLAY=:20.0 now works. Does this value change? Or does someone physically have to change this? Or if I plug the machine in a different monitor does this value change?
If it does, I wonder if I should modify my script to get the display value from the echo $DISPLAY

Could I just also ask one last question?

I have machines running and I am looking after them remotely. I use tight VNC to access them, but I can't actually access the desktop of the running machine.
If I logon as user remotely, I get the warning that the user is already loggod on... but I can still logon.

Now if I logon like this, and execute echo $DISPLAY... will this give me the display value for the user that is running remotely?

Basically, I need to deploy this script to restart the browser to the remote machines, but first need to find out the value of DISPLAY.

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month17 days, 4 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question