Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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}'
running

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
%user1  ALL=(ROOT) NOPASSWD: KVMCMD

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

share|improve this question

1 Answer 1

Answering my own question.

One of the solution would be

Editing (as root) the file

/etc/sudoers

And commenting out the line that says:

Defaults requiretty
share|improve this answer

Your Answer

 
discard

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.