annotate .ssh/onsubnet @ 251:b00e6b403896

Added airline-colour-splits and removed whitespace
author Steve Huston <huston@srhuston.net>
date Wed, 27 Mar 2024 16:31:21 -0400
parents 83f164405755
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
186
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
1 #!/usr/bin/env bash
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
2
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
3 if [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]] || [[ "$1" == "" ]] ; then
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
4 printf "Usage:\n\tonsubnet [ --not ] partial-ip-address\n\n"
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
5 printf "Example:\n\tonsubnet 10.10.\n\tonsubnet --not 192.168.0.\n\n"
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
6 printf "Note:\n\tThe partial-ip-address must match starting at the first\n"
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
7 printf "\tcharacter of the ip-address, therefore the first example\n"
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
8 printf "\tabove will match 10.10.10.1 but not 110.10.10.1\n"
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
9 exit 0
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
10 fi
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
11
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
12 on=0
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
13 off=1
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
14 if [[ "$1" == "--not" ]] ; then
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
15 shift
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
16 on=1
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
17 off=0
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
18 fi
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
19
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
20 regexp="^$(sed 's/\./\\./g' <<<"$1")"
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
21
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
22 if [[ "$(uname)" == "Darwin" ]] ; then
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
23 ifconfig | fgrep 'inet ' | fgrep -v 127.0.0. | cut -d ' ' -f 2 | egrep -q "$regexp"
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
24 else
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
25 hostname -I | tr -s " " "\012" | fgrep -v 127.0.0. | egrep -q "$regexp"
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
26 fi
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
27
251
b00e6b403896 Added airline-colour-splits and removed whitespace
Steve Huston <huston@srhuston.net>
parents: 186
diff changeset
28 if [[ $? == 0 ]]; then
186
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
29 exit $on
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
30 else
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
31 exit $off
83f164405755 New 'onsubnet' command, new config for master controls
Steve Huston <huston@astro.princeton.edu>
parents:
diff changeset
32 fi