【发布时间】:2014-01-30 14:09:51
【问题描述】:
我有 Ubuntu,并且在用户“alex”下运行。我使用 crontab 以 root 身份运行以下 bash 脚本,但是它向我发送了一封电子邮件,并且由于结果不存在,它看起来运行不正确:
/dev/sda - Reallocated_Sector_Ct 是
但是,如果我从 webmin 手动运行 crontab 作业,它可以正常工作。但是当它计划运行时,它就会失败。也许它并没有真正以 root 身份运行?
这是我的代码:
#!/bin/bash
SMARTCHECK=`smartctl -a /dev/sda | grep "Reallocated_Sector_Ct" | awk 'NR==1 {print $10}'`
echo "/dev/sda - Reallocated_Sector_Ct is $SMARTCHECK"
if [ "$SMARTCHECK" != "0" ]; then
mail -s "Failing: /dev/sda" alex <<< "/dev/sda - Reallocated_Sector_Ct is $SMARTCHECK"
fi
谢谢!
【问题讨论】:
-
你是如何将它设置为从 root 启动的?是在root的crontab中,sudo没有密码,其他的吗?
-
第一个猜测是
smartctl不在路径中?并尝试在命令行中使用env -i运行该命令,这样可以吗? -
如果不知道您是如何设置 crontab 的,这是无法回答的。
-
感谢 Wikken,看来我必须添加完整路径 - 我现在正在运行 /usr/sbin/smartctl。我从 webmin 添加了这个 crontab。