Keep your Nightly up-to-date with multirust and a cron job


#1

multirust is great, but I’m not gonna go into how or why here. If you use it and use Rust Nightly, you might find yourself typing multirust update nightly regularly. This can be automated!

On Unix systems, type crontab -e to edit your, well, crontab file. Add a line that looks like this:

0 16    * * *    MULTIRUST_HOME=/home/simon/tmp/multirust PATH="$HOME/tmp/multirust/bin:$PATH" sh -c 'multirust update > /dev/null' 2>&1 | grep -v stable

Several things are going on here:

  • 0 16 * * * means “run this command every day at 4pm, in the machine’s local time zone”. This is a time of day my laptop is likely to be online. There is no need to update more frequently, Nightly is only updated once a day. Use * * * * * instead during initial set up to run every minute, to test that everything works.
  • MULTIRUST_HOME=... is where multirust stores all of its data, including downloaded binaries. I also override this in my shell’s config. If you don’t, skip this.
  • PATH=.../bin:$PATH is where multirust itself is installed. I override this with ./install.sh --prefix ... when installing multirust. I do this so that root access is not required.
  • > /dev/null removes the non-error output. Cron jobs output is emailed to the user (if local email is configured), so we want no output when all is well. I filed issue #50 about adding --quiet as a nicer way to do this.
  • Currently, multirust update emits errors every time because the stable toolchain doesn’t exist yet. 2>&1 | grep -v stable filters out these errors, but keeps others in case something goes wrong. I’ve filed issue #51, but this serves as a work around until it’s fixed on stable is released.

That’s it. Enjoy your always up-to-date Nightly!