Automatic Update Script using Cron, Exit Codes, and Logging
I'm managing multiple machines running Debian, Raspian, and Mint. On some of the machines I want to have updating and upgrading automatically. I've drafted a script that I want to do this and log if the update are successful or not.
#!/bin/bash
captains_log=/home/jason/mission_control/captains.log
apt-get update;
if [ $? == 0 ]; then
apt-get upgrade -y;
if [ $? == 1 ]; then
echo `date`": Daily update failed" >> $captains_log
else
echo `date`": Daily update successful" >> $captains_log
fi
else
echo `date`": Daily update failed" >> $captains_log
fi
I've set the script to run @daily in a root crontab. I run the command manually and it executes as desired. When cron runs the script, I get success in the log but my software is not getting updated.
Can someone tell me where I'm going wrong?
I'm managing multiple machines running Debian, Raspian, and Mint. On some of the machines I want to have updating and upgrading automatically. I've drafted a script that I want to do this and log if the update are successful or not.
#!/bin/bash
captains_log=/home/jason/mission_control/captains.log
apt-get update;
if [ $? == 0 ]; then
apt-get upgrade -y;
if [ $? == 1 ]; then
echo `date`": Daily update failed" >> $captains_log
else
echo `date`": Daily update successful" >> $captains_log
fi
else
echo `date`": Daily update failed" >> $captains_log
fi
I've set the script to run @daily in a root crontab. I run the command manually and it executes as desired. When cron runs the script, I get success in the log but my software is not getting updated.
Can someone tell me where I'm going wrong?
No comments:
Post a Comment