-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportbalancer.sh
94 lines (75 loc) · 2.57 KB
/
portbalancer.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
#Portbalancer Version 1.2
#Author: ae.aguirre@hotmail.com
#Credentials
echo ""
echo -n "Enter Switch IP and press [ENTER]: "
read ip
echo -n "Enter Switch Username and press [ENTER]: "
read user
echo -n "Enter your Switch Password and press [ENTER]: "
read -s pass
printf "\r"
echo -n "Enter Storage Alias (Example: USSECSBVMAX007) and press [ENTER]: "
read alistor
echo -e "\e[92m
########## VERIFY INFORMATION ##########
Swith IP: $ip
Switch Username: $user
Storage Alias: $alistor
########################################
\e[0m";
echo -n "Information Correct?: Y/N "
read aceptar
echo ""
if [ "$aceptar" = "Y" ] || [ "$aceptar" = "y" ]
then
#Collect Logs
echo -n "Gathering info....."
echo ""
sshpass -p $pass ssh $user@$ip alishow |grep -i alias| grep -i $alistor > /tmp/alias_$alistor.txt
sshpass -p $pass ssh $user@$ip cfgactvshow > /tmp/cfgactvshow_$ip.txt
if [ "$?" -eq 0 ];then
#Only alias
storports=$(cat /tmp/alias_$alistor.txt |awk '{print $2}')
cfg=$(cat /tmp/cfgactvshow_$ip.txt)
#Collect alias and wwpn from storage
for iter in $storports;
do
sshpass -p $pass ssh $user@$ip alishow $iter >> /tmp/aliaswwpn_$ip.txt;
done
#Save wwpn and alias in differents files
cat /tmp/aliaswwpn_$ip.txt |grep alias > /tmp/soloalias.txt
cat /tmp/aliaswwpn_$ip.txt |grep -v alias |sed '/^\s*$/d' > /tmp/solowwpn.txt
#Quantity of usage ports by wwpn
cat /tmp/solowwpn.txt |while read a
do
cat /tmp/cfgactvshow_$ip.txt |grep -i $a |wc -l >> /tmp/qty.txt; done
#Show results in console with columns automatically
echo -e "\n"
paste -d'\t' <(printf "%s\n" "Aliases"; awk '{print $2}' /tmp/soloalias.txt) \
<(printf "%s\n" "WWPN"; sed 's/^[[:space:]]*//' /tmp/solowwpn.txt) \
<(printf "%s\n" "Quantity-Ports"; awk '{print $1}' /tmp/qty.txt) | column -t -s $'\t'
else
echo "Invalid Username or Password"
exit
fi
else
exit
fi
#Garabage collector
del="rm -r"
a="/tmp/alias_$alistor.txt"
b="/tmp/cfgactvshow_$ip.txt"
c="/tmp/aliaswwpn_$ip.txt"
d="/tmp/soloalias.txt"
e="/tmp/solowwpn.txt"
f="/tmp/qty.txt"
for kk in "$a" "$b" "$c" "$d" "$e" "$f";
do
if [ -e "$kk" ]; then
$del "$kk"
else :
fi
done
#TODO Check if input is valid