Skip to content

Instantly share code, notes, and snippets.

@arthurattwell
Last active September 14, 2016 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arthurattwell/09ece910915b0c0cf83c11e9aa014e19 to your computer and use it in GitHub Desktop.
Save arthurattwell/09ece910915b0c0cf83c11e9aa014e19 to your computer and use it in GitHub Desktop.
Script to run regular updates to Git repos
#! /bin/bash
#
# ###############################################
# This script updates all my repos regularly.
# It's easier than using cron, where environments
# and permissions are a headache.
# ###############################################
#
# Ask how many seconds to leave between each update.
echo "How many seconds between each update?"
read INTERVAL
# Tell me that you're running.
echo "Running updates every $INTERVAL seconds. Ctrl+C to stop."
# Get the time now
NOW="$(date +%F-%H-%M-%S)"
NOWDATE="$(date +%F)"
NOWTIME="$(date +%H:%M:%S)"
# Create a filename for our log file.
FILE="update-log-$NOW"
# Create a `logs` directory to save to, if it doesn't exist
mkdir -p logs
# Run `mr update` and save the output to the log file.
mr update > logs/$FILE
echo "Last update on $NOWDATE at $NOWTIME"
# Then every interval (i.e. between sleeping for those seconds)...
while sleep $INTERVAL
# ...do the same thing over and over
# resetting the variables each time
do
unset NOW
unset NOWDATE
unset NOWTIME
unset FILE
NOW="$(date +%F-%H-%M-%S)"
NOWDATE="$(date +%F)"
NOWTIME="$(date +%H:%M:%S)"
FILE="update-log-$NOW"
(mr update > logs/$FILE)&
echo "Last update on $NOWDATE at $NOWTIME"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment