0

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?

Thanks.

Maksim Vi.
  • 167
  • 1
  • 1
  • 5

2 Answers2

1

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/execute.sh

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

pQd
  • 29,981
  • 6
  • 66
  • 109
1

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:

DISPLAY=:0.0
# ...
* * * * * 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.

EDIT:

You should also be able to do it like this:

* * * * * export DISPLAY=:0.0 && amarok
Mikael S
  • 2,212
  • 1
  • 16
  • 9