Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 have a small script and I want to run it as user1 in cron. If I am logged in as user1 and execute the script it works just fine, but the moment I try to run it in cron it does not work. If I run the cron as root everything works. Here is what I am doing

Script has below command

sudo virsh list --all | grep myvm | awk '{print $3}'

So if I run it as user1 or put this into a file everything just works. But I add it as

*/5 * * * * user1 /path/to/script

If I run as root in cron it works smooth without sudo * * * * * root /path/to/script

My Sudoers file

Cmnd_Alias KVMCMD = /usr/bin/virsh list --all

I directly cant blame sudoers as manually running the command works (may be because of tty)

share|improve this question
up vote 1 down vote accepted

Answering my own question.

One of the solution would be

Editing (as root) the file


And commenting out the line that says:

Defaults requiretty
share|improve this answer

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.