Skip to content

Instantly share code, notes, and snippets.

@danitfk
Last active November 14, 2018 10:09
Show Gist options
  • Save danitfk/132ed62a65392a3f197551fdd46e96ae to your computer and use it in GitHub Desktop.
Save danitfk/132ed62a65392a3f197551fdd46e96ae to your computer and use it in GitHub Desktop.
It's my own cheat sheet to write bash scripts easily.
# Variables
IP=`ifconfig | grep inet | awk {'print $2'} | grep -Ev "127.0.0.1|:"`
### Ask y/n question
printf "Question? (y/n) "
read answer
if [[ "$answer" == "y" ]]; then
# True condition
else
# False condition
fi
### Check root access
if [ "$(whoami)" != "root" ]; then
echo "Sorry, You must run this script with root privileges"
exit 1
fi
### Check Network connectivity (Internet ping and DNS)
if ping -q -c 1 -W 1 google.com >/dev/null; then
echo "The network is up"
else
echo "The network is down"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment