Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to schedule a gui application in cron, but there is a problem. When cron tries to run the scheduled task (amarok in my case) it throws cannot connect to X server error. I assume it is because the application is executed from my root account. Is it possible to run an application from a root but to pretend to be someone else?


share|improve this question
up vote 1 down vote accepted

Cronjobs run in a very restricted environment, meaning it doesn't know where to find the X server (the $DISPLAY environment variable doesn't exist).

If you want to execute a X application from crontab, you need to first set the $DISPLAY environment variable.

Either call AmaroK like pQd said, or set it for the whole the cron-script:

# ...
* * * * * amarok

Also, I would recommend you to run this as the account you "want to be", rather than root, this is done by running crontab -e as the user.


You should also be able to do it like this:

* * * * * export DISPLAY=:0.0 && amarok
share|improve this answer
Thanks, yeah I am using DISPLAY=:0.0 - works perfect. – Maksim Vi. Nov 22 '09 at 18:08

i think it's bad idea, nevertheless you can execute as root:

su -c 'export DISPLAY=":0.0"; amarok' username

i assume x session is running and you do have user username.

but... you can run from cron scripts as non-root - so why do you insist on invoking it as root? there are also plenty of command-line controlled media players - maybe you do not need amarok after all?

to run script as non-root put in /etc/crontab

25 6    * * *   username /script/you/want/to/

depending on location of commands you'll use you might need to add full path to them.

share|improve this answer
okay, how would I run cron scripts as non-root? So I won't see cannot connect to X server message? – Maksim Vi. Nov 22 '09 at 18:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.