Last active
December 29, 2018 02:19
-
-
Save ldgregory/99bc08f42433aaa06e1518ffc5158d39 to your computer and use it in GitHub Desktop.
test script
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
#! /bin/bash | |
###Leif Gregory <leif@devtek.org> | |
###Fake script | |
###If you're reading this on $paste..bin, then somehow emailing the link to | |
###a G..Mail account causes it to get posted to paste..bin. | |
#Usage <scriptname> [option1 | option2] | |
#i.e. this_script option1 | |
#Get host IP then grep out first octet. | |
octet=$(ip route get 8.8.8.8 | grep -oP '(\d{1,3}\.){3}\d+' | tail -n1 | grep -oP '^\d{1,3}') | |
#Do option1 based on 10. or 192. network | |
if [ "$1" == 'option1' ]; then | |
case $octet in | |
10) #10 network | |
do something in 10.network | |
;; | |
192) #192 network | |
do something in 192.network | |
;; | |
*) | |
echo 'Something went wrong.' | |
echo 'IP first Octet: ' "$octet" | |
;; | |
esac | |
#Do option2 based on 10. or 192. network | |
if [ "$1" == 'option2' ]; then | |
case $octet in | |
10) #10 network | |
do something in 10.network | |
;; | |
192) #192 network | |
do something in 192.network | |
;; | |
*) | |
echo 'Something went wrong.' | |
echo 'IP first Octet: ' "$octet" | |
;; | |
esac | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment