Skip to content

Instantly share code, notes, and snippets.

@dpup
Created December 11, 2012 19:30
Show Gist options
  • Save dpup/4261340 to your computer and use it in GitHub Desktop.
Save dpup/4261340 to your computer and use it in GitHub Desktop.
Script that checks if GitHub is up before running a command
#!/bin/bash
#
# Script that checks GitHub's status API before continuing. If GitHub does not return "good" then
# you will be prompted whether you want to continue.
#
# Information messages are echoed to stderr so it is still possible to pipe the results of stdout to
# a file.
#
# Example Usage:
# $ if-github-up make clean
# $ if-github-up curl -s 'https://status.github.com/api/status.json' > github-status
#
status="$(curl -s 'https://status.github.com/api/status.json')"
if [[ "$status" != *"good"* ]]; then
read -r -p "GitHub may be having problems. Proceed anyway? (yes/y) : " response
response="$(tr A-Z a-z <<< "${response}")"
if [[ ! "${response}" =~ ^(yes|y)$ ]]; then
exit 1
fi
echo "Ok, trying command anyway" >&2
else
echo "GitHub looks good" >&2
fi
echo "Executing \"$@\"" >&2
exec "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment