【问题标题】:admin crontab won't run sudo commandadmin crontab 不会运行 sudo 命令
【发布时间】:2015-07-02 13:55:22
【问题描述】:
sudo: no tty present and no askpass program specified

您好,当我尝试运行以下 crontab 时,我遇到了上述错误。

*/5 * * * * sudo bash /home/admin/scripts/monitor.sh /dev/null 2>&1

我使用 nano 作为编辑器来编辑管理员用户 crontab - 注意这不是 root 用户。

EDITOR=nano crontab -e -u 管理员

【问题讨论】:

  • 为什么这个脚本需要 sudo?您每次都必须提供密码或更改 /etc/sudoers
  • @AndreySabitov 我是否更改此行#Defaults requiretty
  • monitor.sh 脚本以 #! /bin/bash?
  • 我让它工作,通过将它移动到 root 用户运行

标签: crontab root cron-task


【解决方案1】:

1) 在 sudoers 文件中禁用 requiretty

2) 允许无密码执行脚本:

admin    ALL=(ALL) NOPASSWD: /home/admin/scripts/monitor.sh

3) 我不确定,但您不需要在 sudo 之后指定 bash。只需添加#! /bin/bash 在脚本的开头

*/5 * * * * sudo /home/admin/scripts/monitor.sh /dev/null 2>&1

【讨论】:

  • 三合一——(2)请!
猜你喜欢
  • 2018-07-26
  • 2017-08-05
  • 1970-01-01
  • 1970-01-01
  • 2018-07-17
  • 1970-01-01
  • 2019-01-10
  • 2012-07-29
  • 2014-12-03
相关资源
最近更新 更多