sudo: sorry, you must have a tty to run sudo

通过

[simonsun@magic ~]$ crontab -e
crontab: installing new crontab
[simonsun@magic ~]$ crontab -l
10 11 11 4 * /home/simonsun/Desktop/shutdown.sh

添加了一个自动关机的任务:

#!/bin/sh
sudo /sbin/shutdown -h now

但并没有成功,收到了系统的一封信:

[simonsun@magic ~]$ cat /var/spool/mail/simonsun
From simonsun@magic.linux  Sun Apr 11 11:10:02 2010
Return-Path: <simonsun@magic.linux>
Received: from magic.linux (magic.linux [127.0.0.1])
        by magic.linux (8.13.8/8.13.8) with ESMTP id o3B3A1L7005990
        for <simonsun@magic.linux>; Sun, 11 Apr 2010 11:10:02 +0800
Received: (from simonsun@localhost)
        by magic.linux (8.13.8/8.13.8/Submit) id o3B3A1LU005989;
        Sun, 11 Apr 2010 11:10:01 +0800
Date: Sun, 11 Apr 2010 11:10:01 +0800
Message-Id: <201004110310.o3B3A1LU005989@magic.linux>
From: root@magic.linux (Cron Daemon)
To: simonsun@magic.linux
Subject: Cron <simonsun@magic> /home/simonsun/Desktop/shutdown.sh
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/simonsun>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=simonsun>
X-Cron-Env: <USER=simonsun>

sudo: sorry, you must have a tty to run sudo

 

随后查找资料,修改一下好了:注释掉 /etc/sudoers中 ‘Defaults requiretty ’。
[simonsun@magic ~]$ sudo visudo
[simonsun@magic ~]$

参考连接:

http://hi.baidu.com/powersaven/blog/item/605c7344f25a8a2dcefca3fd.html

http://www.question-defense.com/2009/03/23/sudo-sorry-you-must-have-a-tty-to-run-sudo

http://linux.chinaunix.net/bbs/viewthread.php?tid=901336

 

注:最好这样写: #crontab -e

10 11 11 4 * sh /home/simonsun/Desktop/shutdown.sh

,否则系统有时候会报/bin permission denied.

 

你可能感兴趣的:(linux,PHP,.net,sun,bbs)