James' Notes
Raspberry Pi Grim Dawn

Automatic Daily Package Update Script

Upgrade linux and reboot if necessary.

sudo apt-get update && sudo apt-get -y dist-upgrade
sudo reboot

Prepare folders for the automatic update script and log files.

mkdir -p ~/Scripts/Data/Logs

Create a new file CheckUpdate.sh

nano ~/Scripts/CheckUpdate.sh

and paste the following bash script into it.

#!/bin/bash

MYOUTPUT=/home/james/Scripts/Data/Logs

timestamp=`date '+%y-%m-%d'`

sudo apt update -y > $MYOUTPUT/Update_$timestamp.txt

apt list --upgradeable > $MYOUTPUT/Avail_$timestamp.txt

if [ ! -f $MYOUTPUT/Avail_$timestamp.txt ]; then
    echo "File not Found!"
    exit
fi

count=`wc -l $MYOUTPUT/Avail_$timestamp.txt | cut -d' ' -f1`

if (( $count < 2 ))
then
    exit
fi

sudo apt upgrade -y > $MYOUTPUT/Upgrade_$timestamp.txt
sudo apt full-upgrade -y >> $MYOUTPUT/Upgrade_$timestamp.txt
sudo apt autoremove -y >> $MYOUTPUT/Upgrade_$timestamp.txt
sudo apt clean -y >> $MYOUTPUT/Upgrade_$timestamp.txt

sudo reboot now

Make this script executable

chmod +x ~/Scripts/CheckUpdate.sh

Edit the crontab file

sudo crontab -e

and add the following lines to the end of the file to allow the above script to run automaticly every day.

50 5 * * * /home/james/Scripts/CheckUpdate.sh 2>/dev/null &