Last active
November 14, 2018 10:09
-
-
Save danitfk/132ed62a65392a3f197551fdd46e96ae to your computer and use it in GitHub Desktop.
It's my own cheat sheet to write bash scripts easily.
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
# 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