Skip to content

Instantly share code, notes, and snippets.

@danaketh
Last active August 29, 2015 14:06
Show Gist options
  • Save danaketh/52f8e1634b370a5445b1 to your computer and use it in GitHub Desktop.
Save danaketh/52f8e1634b370a5445b1 to your computer and use it in GitHub Desktop.
Nasty Bash alternative to https://github.com/sindresorhus/is-up
is-up() {
is_up_url="http://isitup.org/$1.json"
is_up_json=$(curl -s ${is_up_url})
is_up_status=$(expr "${is_up_json}" : '.*"status_code": \([0-9]\)')
if [ ${is_up_status} -eq 1 ];
then
echo -e "\e[32m✓\e[0m \e[37m$1\e[0m \e[32mis up\e[0m"
else
echo -e "\e[31m×\e[0m \e[37m$1\e[0m \e[31mis down\e[0m"
fi
}
alias is-up=is-up
#!/bin/bash
# Simple (and nasty) bash alternative to https://github.com/sindresorhus/is-up
url="http://isitup.org/$1.json"
json=$(curl -s ${url})
status=$(expr "${json}" : '.*"status_code": \([0-9]\)')
if [ ${status} -eq 1 ];
then
echo -e "\e[32m✓\e[0m \e[37m$1\e[0m \e[32mis up\e[0m"
else
echo -e "\e[31m×\e[0m \e[37m$1\e[0m \e[31mis down\e[0m"
fi
@danaketh
Copy link
Author

I didn't bothered with escaping the special character or anything. It's ugly, it's nasty but it works and you don't need any fancy stuff around...

And yes, you don't have to use .bashrc, it works well in .zshrc too (tested as I use ZSH).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment