Bij*_*ijo 4 scripting sudo cron
我可以无密码访问服务器。我的用户帐户已添加到sudoers文件中,用于 /etc/init.d/ 中某些服务/守护程序的NOPASSWD使用。
我想根据一些测试结果编写一个脚本来启动或停止一个守护进程。我已经设置了一个 cron 来在特定时间运行这个脚本。但它返回错误“sudo: no tty present and no askpass program specified”。
我可以在终端中使用“ sudo /etc/init.d/service name start/stop而无需密码。我没有root密码。
我已经仔细检查了 /etc/sudoers 文件。没有“要求”。我正在使用 Ubuntu-10.04 、 2.6.32-24-generic。
以下是 sudoers 中的活动行:
Defaults env_reset
root ALL=(ALL) ALL
bijo ALL=NOPASSWD: /etc/init.d/apache2
%sudo ALL=(ALL) ALL
%admin ALL=(ALL) ALL
Run Code Online (Sandbox Code Playgroud)
如果您以与没有密码访问权限的用户相同的用户身份运行脚本,那么它应该可以正常工作,我将确保脚本以正确的用户身份运行,我还将通过手动调用脚本来测试脚本正确的用户。
您可能还需要检查 sudoers 文件中是否不存在以下行,或者您还有另一行说明您的用户不需要 TTY
Defaults requiretty
Run Code Online (Sandbox Code Playgroud)
如果存在该行,您可以将其注释掉(不是一个好主意),最好在其中添加以下内容
Defaults:<USERNAME> !requiretty
Run Code Online (Sandbox Code Playgroud)
其中 USERNAME 是您的用户
归档时间: |
|
查看次数: |
6342 次 |
最近记录: |