Mercurial > index.cgi > dotfiles
comparison .ssh/onsubnet @ 186:83f164405755
New 'onsubnet' command, new config for master controls
| author | Steve Huston <huston@astro.princeton.edu> |
|---|---|
| date | Tue, 03 Mar 2020 16:48:59 -0500 |
| parents | |
| children | b00e6b403896 |
comparison
equal
deleted
inserted
replaced
| 185:daa1d18ece79 | 186:83f164405755 |
|---|---|
| 1 #!/usr/bin/env bash | |
| 2 | |
| 3 if [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]] || [[ "$1" == "" ]] ; then | |
| 4 printf "Usage:\n\tonsubnet [ --not ] partial-ip-address\n\n" | |
| 5 printf "Example:\n\tonsubnet 10.10.\n\tonsubnet --not 192.168.0.\n\n" | |
| 6 printf "Note:\n\tThe partial-ip-address must match starting at the first\n" | |
| 7 printf "\tcharacter of the ip-address, therefore the first example\n" | |
| 8 printf "\tabove will match 10.10.10.1 but not 110.10.10.1\n" | |
| 9 exit 0 | |
| 10 fi | |
| 11 | |
| 12 on=0 | |
| 13 off=1 | |
| 14 if [[ "$1" == "--not" ]] ; then | |
| 15 shift | |
| 16 on=1 | |
| 17 off=0 | |
| 18 fi | |
| 19 | |
| 20 regexp="^$(sed 's/\./\\./g' <<<"$1")" | |
| 21 | |
| 22 if [[ "$(uname)" == "Darwin" ]] ; then | |
| 23 ifconfig | fgrep 'inet ' | fgrep -v 127.0.0. | cut -d ' ' -f 2 | egrep -q "$regexp" | |
| 24 else | |
| 25 hostname -I | tr -s " " "\012" | fgrep -v 127.0.0. | egrep -q "$regexp" | |
| 26 fi | |
| 27 | |
| 28 if [[ $? == 0 ]]; then | |
| 29 exit $on | |
| 30 else | |
| 31 exit $off | |
| 32 fi |
