Intro: Raspberry Pi Auto Update (Updated)
If you're like me, you want automatic updates for your Raspberry Pi setup. This of course would only be needed if you setup a media server like Plex, OSMC, or KODI.
This really takes the hassle of updating this server since the main purpose of a media server is to be a set-top box. There are a couple of ways to do this, but the one that will be used in the Instrucable is setting up a cron job.
First of all, I set my Raspberry Pi up using the inscrutable below:
This has been updated so that logging works properly.
Step 1: Step 1: Update.sh
You will need to create a shell script as a first step. This script will update everything on your Raspberry Pi when run. It will also remove and clean any files and dependencies that aren't being used. This will save some space on the SD card and is a good practice to ensure that you don't have anything unnecessary on your Raspberry Pi.
This script will also update your Raspberry Pi firmware.
First, create a file in the root user (pi if you kept this account) using the command below:
sudo nano update.sh
Add the following lines of code to the file and save it (ctrl + X, Y and enter). This will the basis for the automatic updates:
#!/bin/sh sudo apt-get update && sudo apt-get upgrade -y sudo rpi-update sudo apt-get autoremove sudo apt-get autoclean sudo reboot
You will want to make the shell script executable using the following command:
sudo chmod +x update.sh
Step 2: Step 2: Cron
Optional: Create a folder to store a running log file for when this runs every week.
(This log folder and the file created below can be anything you want to name it and in any location)
sudo mkdir /logs
This will create a new folder or directory in location you're at (i.e. /home/pi/logs/). If you want to create a folder that is in root, just put a ~ in front of /logs.
To make the entry to cron, we will need to add the following to the crontab file using the following command and selecting option 2:
The cron job will look similar to what is below. This depends on if you
want a log file created after each run (remove '>/home/pi/logs/cronlog')This will run once a week on Saturday at midnight. To create the cronlog file, just enter the following (you may need to use sudo):
Add the following line at the bottom and save (ctrl X, Y and enter):
0 0 * * SAT sh /home/pi/update.sh 2>/home/pi/logs/cronlog
The 2> redirects all output to the file so that you will have a complete log.
For examples on the syntax of this line of code, head over to
Step 3: Step 3: Troubleshooting
One issue I ran into doing this had to mostly with installing software from the repository once it was updated, although this isn't all that related. The following command might not work:
sudo apt-get install <software>
You might have to specify the distro in order for them to install:
sudo apt-get install <software> -t jessie
If you want to view the log file that was created during the cron job, use one of the following commands:
Let me know about any other issues that come up.
Pictures to follow.