-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstation-toggle.sh
executable file
·46 lines (40 loc) · 1.22 KB
/
station-toggle.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
## ##
## Use this script to toggle a set of stations on or off ##
## ##
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
function usage() {
echo "$0 -a up -s staX,staY,staZ..."
echo " to turn stations on"
echo "$0 -a down -s staX,staY,staZ..."
echo " to turn stations off"
}
action=none
stations=""
while getopts ":a:s:" opt ; do
case "${opt}" in
a) action="${OPTARG}";;
s) stations="${OPTARG}";;
*) exit 1;;
esac
done
shift $(( OPTIND - 1 ));
[ -z "$stations" ] && echo "No stations specified." && usage && exit 1
[[ $action = none ]] && echo "No action specified." && usage && exit 1
scriptdir="/home/lanforge/scripts"
portmod="$scriptdir/lf_portmod.pl"
cd $scriptdir
IFS=',' sta_list=($stations)
if [[ $action = up ]] || [[ $action = down ]] ; then
for sta in "${sta_list[@]}"; do
echo "station $sta $action"
$portmod --port_name $sta --set_ifstate $action --quiet 1
done
exit 0
else
echo "What does action $action mean?"
usage
exit 1
fi
#