freddiefujiwra Asked: 2009-05-27 17:35:18 +0800 CST2009-05-27 17:35:18 +0800 CST 2009-05-27 17:35:18 +0800 CST the error occured a command in sudo from crontab 772 When I execute shell, but it is carried out by cron "sudo: sorry, you must have a tty to run sudo" appears. but how should this have dealt? cron sudo 3 Answers Voted gigawatt 2010-02-24T08:17:42+08:002010-02-24T08:17:42+08:00 You can also simply reconfigure sudo to not require a tty by: Editing (as root) the file /etc/sudoers And commenting out the line that says: Defaults requiretty Best Answer LapTop006 2009-05-27T18:15:20+08:002009-05-27T18:15:20+08:00 You don't need sudo to run programs as other users in cron (at least with the system crontab). Just change the user field from root to the target user. If you really want su does work in cron. pgs 2009-06-03T08:01:26+08:002009-06-03T08:01:26+08:00 You can add NOPASSWD: to the relevant entry in the sudoers file to stop it asking for a password, which I think will help. You're better off running it from the crontab of the desired user in the first place, and avoiding the need for sudo. To edit fred's crontab: su - fred crontab -e
You can also simply reconfigure sudo to not require a tty by:
Editing (as root) the file
And commenting out the line that says:
You don't need sudo to run programs as other users in cron (at least with the system crontab).
Just change the user field from root to the target user.
If you really want su does work in cron.
You can add
NOPASSWD:
to the relevant entry in the sudoers file to stop it asking for a password, which I think will help.You're better off running it from the crontab of the desired user in the first place, and avoiding the need for sudo.
To edit fred's crontab: