【发布时间】:2016-06-24 09:20:45
【问题描述】:
我的脚本产生了一些非常奇怪的输出,我不知道为什么。
这是脚本: (userslist.temp 是一个用户名列表,文件的每一行一个)
printf 'Output Starting:\n\n'
while read line; do
cronresult=$(sudo crontab -u $line -l)
printf "$line : $cronresult"
done < userslist.temp
它产生的输出:
Output Starting:
no crontab for thornegarvin
thornegarvin :
no crontab for testuserone
testuserone :
no crontab for testusertwo
testusertwo :
no crontab for testuserthree
testuserthree :
我的用户没有配置 crontab,但我不知道为什么脚本没有在单独的行上打印变量。
【问题讨论】:
-
如果你通过
2>/dev/null丢弃stderr会发生什么? -
您的问题到底是什么?没有配置 crontab,我不明白你会看到什么?
-
$(..)捕获标准输出,而像这样的错误消息直接写入标准错误信息到屏幕。如果您还想在变量中存储错误,可以使用cronresult=$(sudo crontab -u "$line" -l 2>&1)