Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 am trying to have the following cron executed with a certain user.

U=`/usr/bin/w | grep -w :0 | awk '{ print $1 }'`
*/1 * * * * $U /opt/script.sh

It seems the deamon doesn't know how to interpret this command; I get :

/usr/sbin/cron[18698]: (CRON) bad username (/etc/cron.d/script)

Is there any way to do this ?

share|improve this question

No, a crontab file is not a shell script you can't just introduce arbitrary commands or variables. If you want to do this, run the script as root and change users in the script.

To determine sessions have a look at consolekit which you can use to get all active sessions on your system either via dbus or ck-list-sessions

share|improve this answer
Ok, thank you for your answer. To have this working I used crontab /opt/cronjob in the bash_profile – igor012 Aug 3 '12 at 14:54

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.