简体   繁体   中英

Output apt-get upgrade to text

I've written a script for updating ubuntu packages and to email me however the output of the what's been upgrade and services restarted does not get emailed or produced. I've tried to run the update from the command line and output to a text file but still nothing gets written to the text file. Any ideas?

TEMP="/tmp/upgrade.txt"
MAIL_ADDR="user@example.com"
cat /dev/null > $TEMP
apt-get update && apt-get upgrade --assume-yes > $TEMP
mail -s "Upgrade for $HOSTNAME" $MAIL_ADDR < $TEMP
rm $TEMP

Just using '&>' redirect in your apt-get commands would fix this issue.

apt-get update &>$TEMP
apt-get upgrade --assume-yes &>> $TEMP

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM