Last active
September 14, 2016 05:28
-
-
Save arthurattwell/09ece910915b0c0cf83c11e9aa014e19 to your computer and use it in GitHub Desktop.
Script to run regular updates to Git repos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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