【发布时间】:2016-09-19 02:49:21
【问题描述】:
我使用下面的 Bash 脚本更新 OSX 上的软件,并在必要时重新启动。
奇怪的是,当发现不需要软件更新时,运行脚本的输出和日志都不包含部分输出。
例如,如果我在不需要更新的机器上运行以下命令,我会看到:
% softwareupdate -i -a
Software Update Tool
Copyright 2002-2012 Apple Inc.
Finding available software
No updates are available.
最后一行“没有可用的更新”是未记录到以下脚本的日志文件中的内容:
#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin export PATH
SWLOG=/var/log/swupdate.log
(
echo "################ SoftwareUpdate Script Beginning at $(date) ################"
echo "Script Name: $(basename -- "$0") "
softwareupdate -l | grep -i "restart"
if [[ $? -eq 0 ]] #reboot will be needed
then
echo "Software update requiring reboot is needed"
echo "Starting..."
softwareupdate -i -a
echo "################ Rebooting at $(date) ################"
reboot
else
echo "No reboot needed. Updates will be applied if needed..."
softwareupdate -i -a
echo "################ SoftwareUpdate Script Ending at $(date) ################"
echo
fi
exit 0
) | tee -a $SWLOG
相反,日志显示:
################ SoftwareUpdate Script Beginning at Sat May 21 19:37:44 PDT 2016 ################
Script Name: swupdate.sh
No reboot needed. Updates will be applied if needed...
Software Update Tool
Copyright 2002-2012 Apple Inc.
Finding available software
################ SoftwareUpdate Script Ending at Sat May 21 19:38:33 PDT 2016 ################
并省略“没有可用的更新”。
任何想法,建议为什么会发生这种情况?我想记录下这个重要的细节。
提前致谢,丹
【问题讨论】:
-
可能是因为在脚本中找不到“没有可用的更新”字符串?
-
@n.m.请解释一下
-
我认为“没有可用的更新”可能已发送到标准错误。你试过
softwareupdate -i -a 2>&1
标签: bash macos shell unix stderr