UpdateRstudio.md

Automatically Update Rstudio

Information on package downloads were obtained from the RStudio website, and this automation was prompted by a question asked by a student on GitHub.

Step 1. Write your script

I like to keep my automation scripts in ~/scripts, but you may have a different personal preference. In any case, the script I wrote is as follows:

echo "Commencing RStudio update on" $(date +"%A %b %d, %Y") at $(date +"%r")
cd /home/shinshaw/Downloads
mkdir rstudio && cd rstudio
wget -O rstudio.deb http://www.rstudio.org/download/latest/preview/desktop/ubuntu64/rstudio-latest-amd64.deb
sudo dpkg -i rstudio.deb
cd /home/shinshaw/Downloads
rm -r rstudio/

Notes:

Make sure the script you've saved is executable. For me, this was:

chmod +x ~/scripts/updateRstudio.sh

Step 2. Schedule Script

Next, you'll need to schedule this script to run at a given time. I've chosen to update my RStudio build at 4am on Sunday morning. This should make pretty certain that I'm not running into any errors. Now, it is very important that we access the root crontab scheduler, and not your personal crontab scheduler, as we'll be installing packages which requires elevated permissions. In terminal, type:

sudo crontab -e

This will open crontab in your default text editor, nano for me. In crontab, add a line such as:

00 04 * * 7 /home/shinshaw/scripts/updateRstudio.sh >> /home/shinshaw/scripts/logs/updateRstudio.log 2>&1

Let's work through this line:

  1. 00 04 * * 7
    • This tells crontab when to run. Check the crontab manual (or ) for further details.
  2. /home/shinshaw/scripts/updateRstudio.sh
    • This tells crontab to execute my script
  3. >> /home/shinshaw/scripts/logs/updateRstudio.log 2>&1
    • This tells crontab to save the stdout of my script to ~/scripts/logs/updateRstudio.log, and 2>&1 tells it to include stderr as well.

Then, save your crontab file and you're done! Congratulations!



samhinshaw/labnotebook documentation built on May 29, 2019, 1:02 p.m.