We help IT Professionals succeed at work.

Crontab not working

zeraxis_ee asked
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
Watch Question

Top Expert 2009

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
Deepak KosarajuDevOps Engineer

Try this which works......
*/15 * * * * /bin/sh /home/zx_user/MMTVCentre/restartbrowser.sh
Top Expert 2007

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
Maciej Ssysadmin

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.


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?
Top Expert 2009

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/

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


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
Top Expert 2009

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 ??
Maciej Ssysadmin

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:


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?


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

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.


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.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.