Last active
August 29, 2015 14:06
-
-
Save danaketh/52f8e1634b370a5445b1 to your computer and use it in GitHub Desktop.
Nasty Bash alternative to https://github.com/sindresorhus/is-up
This file contains hidden or 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
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 |
This file contains hidden or 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 | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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).