#!/bin/bash
#set -x
#====================================================================
#@(#) Script to generate a HTML report on Brocade SAN switches
# format of line before HMTL :
# html_tag;nagios_tag;reserved;output
#====================================================================
# version 1.0 02-2018 eif
# version 1.1 02-2024 eif add port signal strength
dir=`dirname $0`
#. $dir/.env
# global variables for all scripts
export sn=`basename $0 | cut -d. -f1`
export HOSTNAME=`/bin/hostname`
logpath=./logs
export logname=$logpath/$sn.log
TMPFILE=$logpath/tempo_file
month=$(date "+%Y-%m")
archpath=/storage/san/backup/$month
os=$(uname -s | tr 'A-Z' 'a-z')
USER=report
listswitch="swsan01 swsan02" # All SAN switches from all fabric separated by space
#NAGIOSTAG="0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN"
COLOR[0]="#57E964" # green
COLOR[1]="#F87217" # orange #F7BE81
COLOR[2]="#FF2400" # red #DF013A
COLOR[3]="yellow" # yellow #F3F781
COLOR[4]="#86EFF6" # blue
COLOR[5]="#FFFFFF" # white
#FFA500 : orange
#COLOR[6]="#33CAFF" # Blue SAN blue
COLOR[6]=" #85C1E9" # Blue SAN blue
COLOR[7]="#E77471" # Light Coral for SAN red
TAG=TAG # reserved for future
TMPFILE=$logpath/santemp
#----------------------------
initialize ()
{
echo "# Initialize"
mkdir -p $logpath > /dev/null 2>&1
rm $logpath/*configshow* > /dev/null 2>&1
rm $logpath/*switchshow* > /dev/null 2>&1
rm $logpath/swsan* > /dev/null 2>&1
rm $logpath/san* > /dev/null 2>&1
rm $logpath/san_full* > /dev/null 2>&1
rm $TMPFILE* > /dev/null 2>&1
}
#----------------------------
grepp ()
{
x=$1
y=$2
if [ $os == "aix" ]
then
cat $y | tr -d "\015" | tr -d "\011" | tr -d "\044" | sed 's/^ *$//' | grep -p "$x"
else
if [ $os == "linux" ]
then
cat $y | tr -d "\015" | tr -d "\011" | tr -d "\044" | sed 's/^ *$//' | awk -v RS="" "/$x/"
else
echo "ERROR: Unknown OS"
exit 1
fi
fi
}
#----------------------
get_fids ()
{
for sw in $(cat $list)
do
echo "######## $sw ########"
${SSH}$sw 'lscfg --show' > $logfile
fids=$(cat $logfile | grep '|' | sed 's/^\ //' | cut -d' ' -f2- | sed 's/|/\ /g' | tr -s ' ' | tr ' ' '\n' | sort -u | sed '/^$/d' | tr '\n' ' ')
echo "FID : $fids"
done
### fosexec --fid 2 -cmd "switchshow"
}
#----------------------------
list_switch_ports_signal ()
{
fabric=fabric
for sw in $(echo $listswitch)
do
echo "######## $sw"
ssh $USER@$sw "sfpshow -all" > $logpath/sfpshow_${fabric}.csv
done
}
#----------------------------
list_switch_ports ()
{
fabric=fabric
for sw in $(echo $listswitch)
do
echo "######## $sw"
ssh $USER@$sw "configshow" | egrep "^alias|^zone|^cfg|^enable" > $logpath/configshow_${fabric}.csv
fabricname=$(grep -i '^enable:' $logpath/configshow_${fabric}.csv | awk -F':' '{print $2}')
ssh $USER@$sw "switchshow" | tr -s ' ' | sed 's/\ /;/g' | sed 's/[^A-Za-z0-9_.;:-]//g' | tr -s '\;' ';' > $TMPFILE.tempo
switchname=$(grep -i '^switchName:' $TMPFILE.tempo | awk -F':' '{print $2}' | tr 'A-Z' 'a-z')
swdomain=$(grep -i '^switchDomain:' $TMPFILE.tempo | awk -F':' '{print $2}')
ssh $USER@$sw "sfpshow -all" > $logpath/sfpshow-all_${fabricname}_${switchname}_full
cat $logpath/sfpshow-all_${fabricname}_${switchname}_full | egrep 'Slot|Power' | sed 's/^Slot/\n/g' | tr -s ' ' | sed 's/^\ //g' | sed 's/Port\ //' | sed 's/\//;/' | sed 's/:/;/' > $logpath/sfpshow-all_${fabname}_${switchname}
ssh $USER@$sw "sfpshow" | tr -s ' ' | sed 's/\ //g' | sed 's/Slot//' | sed 's/Port//' | cut -d':' -f1,5 | sed 's/\//;/' > $logpath/sfpshow_${fabricname}_${switchname}
echo "H3;0;TAG;FABRIC: $fabricname SWITCHNAME: $switchname" > $logpath/switchshow_${fabricname}_${switchname}.csv
echo "TH;4;TAG;Index;Slot;Port;Speed;State;Protocol;Type;WWN;Alias;Zoned;SFP_speed;RXpower;TXpower" >> $logpath/switchshow_${fabricname}_${switchname}.csv
if [ $(grep -qi '^Index;Port;' $TMPFILE.tempo; echo $?) -eq 0 ]
then
slot=";NA"
cat $TMPFILE.tempo | sed -e "/;/ s/;/${slot};/2" | sed 's/^;//' | sed 's/^/;/' | grep -v ";FC;Router" > $logpath/switchshow_${fabricname}_${switchname}
rm $TMPFILE.tempo
else
cat $TMPFILE.tempo | sed 's/^;//' | sed 's/^/;/' | grep -v ";FC;Router" > $logpath/switchshow_${fabricname}_${switchname}
rm $TMPFILE.tempo
fi
for line in $(cat $logpath/switchshow_${fabricname}_${switchname} | grep "FC" | grep -v '^FC' | cut -d';' -f1-4,7-)
do
port=$(echo $line | cut -d';' -f3,4)
sfpspeed=$(grep "^${port}:" $logpath/sfpshow_${fabricname}_${switchname} | cut -d':' -f2 | tr ' ' '\n' | grep _Gbps | sed 's/_Gbps//' | rev | cut -d',' -f1 | rev)
if [ "$sfpspeed" == "" ]
then
sfpspeed="NA"
fi
############################
rxpower=$(grepp "^${port};" $logpath/sfpshow-all_${fabricname}_${switchname} | grep "RX Power" | cut -d';' -f2- | sed 's/\ dBm\ /|dBm|/g')
txpower=$(grepp "^${port};" $logpath/sfpshow-all_${fabricname}_${switchname} | grep "TX Power" | cut -d';' -f2- | sed 's/\ dBm\ /|dBm|/g')
# get color for fabric
NAGIOSTAG=0
# for linux suff=$(echo $fabricname | tr [:alpha:] ' ' | awk '{print $1}')
suff=$(echo $fabricname | rev | cut -c1)
modulo=$(echo $(($suff % 2)) )
if [ "$modulo" -eq 0 ]
then
NAGIOSTAG=6
else
if [ $(echo $fabricname | grep -qi red;echo $?) -eq 0 ]
then
NAGIOSTAG=7
fi
fi
TAG=TAG
prefix="TD;$NAGIOSTAG;$TAG"
zone="no"
if [ $(echo $line | cut -d';' -f6 | grep -v "Online" > /dev/null; echo $?) -eq 0 ]
then
# Ports offline or no FC module
begin=$(echo $line | cut -d';' -f1-7)
wwn=""
alias=""
rxpower=""
txpower=""
echo "${prefix}${begin};;${wwn};${alias};${zone};${sfpspeed};${rxpower};${txpower}" >> $logpath/switchshow_${fabricname}_${switchname}.csv
else
if [ $(echo $line | egrep "E-Port" > /dev/null; echo $?) -eq 0 ]
then
line1=$(echo $line | sed 's/;LS;/;/' | sed 's/;LE;/;/' | sed 's/;LD;/;/')
# Port type E-Port
begin=$(echo $line1 | cut -d';' -f1-8)
wwn=$(echo $line1 | cut -d';' -f9)
if [ $(echo $wwn | sed 's/[^:]//g' | awk '{ print length }') -eq 7 ]
then
alias=$(echo $line1 | cut -d';' -f10- | sed 's/;/|/g')
else
wwn=""
alias=$(echo $line1 | cut -d';' -f9- | sed 's/;/|/g')
fi
echo "${prefix}${begin};${wwn};${alias}(ISL);${zone};${sfpspeed};${rxpower};${txpower}" >> $logpath/switchshow_${fabricname}_${switchname}.csv
else
if [ $(echo $line | egrep "L-Port|NPIV" > /dev/null; echo $?) -eq 0 ]
then
# Port type L-Port or N-Port (NPIV)
begin=$(echo $line | cut -d';' -f1-8 | sed 's/F\-Port/NPIV/')
index=$(echo $line | cut -d';' -f2 | sed 's/;/,/')
ssh $USER@$sw "portshow -i $index" > $logpath/portshow_tmp
for wwn in $(grepp "portWwn:" $logpath/portshow_tmp | grep -v "portWwn" | awk '{print $1}' | sed '/^$/d' | egrep -vi "port|distance")
do
if [ $(echo $wwn | tr -s ':' '\n' | wc -l | awk '{print $1}') == 8 ]
then
zone="no"
alias=$(grep "$wwn" $logpath/configshow_${fabric}.csv | grep alias | cut -d':' -f1 | sed 's/alias\.//')
if [ $(cat $logpath/configshow_${fabric}.csv | grep '^zone.' | cut -d':' -f2- | sed -e 's/^/;/' -e 's/$/;/' | grep ";${alias};" > /dev/null; echo $?) -eq 0 ]
then
zone="yes"
fi
if [ $(echo $alias | tr -s ' ' '\n' | wc -l | awk '{print $1}') -ne 1 ]
then
alias=$(echo $alias | sed 's/\ /,/g' | sed 's/$/(multiples_alias)/')
else
if [ -z ${alias} ]
then
alias="(no_alias)"
fi
fi
echo "${prefix}${begin};${wwn};${alias};${zone};${sfpspeed};${rxpower};${txpower}" >> $logpath/switchshow_${fabricname}_${switchname}.csv
fi
done
rm -f $logpath/portshow_tmp
else
if [ $(echo $line | grep "F-Port" > /dev/null; echo $?) -eq 0 ]
then
# Port type F-Port
begin=$(echo $line | cut -d';' -f1-8)
wwn=$(echo $line | cut -d';' -f9)
alias=$(grep "$wwn" $logpath/configshow_${fabric}.csv | grep alias | cut -d':' -f1 | sed 's/alias\.//')
if [ $(cat $logpath/configshow_${fabric}.csv | grep '^zone.' | cut -d':' -f2- | sed -e 's/^/;/' -e 's/$/;/' | grep ";${alias};" > /dev/null; echo $?) -eq 0 ]
then
zone="yes"
fi
if [ $(echo $alias | tr -s ' ' '\n' | wc -l | awk '{print $1}') -ne 1 ]
then
alias=$(echo $alias | sed 's/\ /,/g' | sed 's/$/(multiples_alias)/')
else
if [ -z ${alias} ]
then
port=$(echo $line | cut -d';' -f2)
domport=$(echo "${swdomain},${port}" | rev)
alias=$(cat $logpath/configshow_${fabric}.csv | grep alias | rev | grep "^$domport:" | cut -d':' -f2 | cut -d'.' -f1 | rev)
if [ $(cat $logpath/configshow_${fabric}.csv | grep '^zone.' | cut -d':' -f2- | sed -e 's/^/;/' -e 's/$/;/' | grep ";${alias};" > /dev/null; echo $?) -eq 0 ]
then
zone="yes"
fi
if [ -z ${alias} ]
then
alias="(no_alias)"
fi
fi
fi
echo "${prefix}${begin};${wwn};${alias};${zone};${sfpspeed};${rxpower};${txpower}" >> $logpath/switchshow_${fabricname}_${switchname}.csv
else
begin=$(echo $line | cut -d';' -f1-8)
wwn=$(echo $line | cut -d';' -f9)
alias="(unknown_type)"
echo "${prefix}${begin};${wwn};${alias};${zone};${sfpspeed};${rxpower};${txpower}" >> $logpath/switchshow_${fabricname}_${switchname}.csv
fi
fi
fi
fi
done
# rm $logpath/switchshow_${fabricname}_${switchname}
mv $logpath/switchshow_${fabricname}_${switchname}.csv $logpath/swsan_${fabricname}_switchshow_${switchname}.csv
mv $logpath/configshow_${fabric}.csv $logpath/swsan_${fabricname}_configshow_${switchname}.csv
done
}
#----------------------------
alias_unused ()
{
# Alias unused
NAGIOSTAG=0
TAG=TAG
allfabric=""
for fabricname in $(ls $logpath/swsan_*_configshow_*.csv | rev | cut -d'/' -f1 | cut -d'.' -f2 | rev | sed -e 's/swsan_/\ /' -e 's/_configshow_/\ /' | awk '{print $1}' | sort -u)
do
allfabric=$(echo $allfabric $fabricname)
filename=$(ls $logpath/swsan_${fabricname}_configshow_*.csv | head -1)
cat /dev/null > $logpath/san_result.csv
for i in $(ls $logpath/swsan_${fabricname}_switchshow_*.csv)
do
cat $i | grep '^TD;' | rev | cut -d';' -f2- | rev >> $logpath/san_result.csv
done
echo "H3;0;TAG;Alias defined in Fabric ${fabricname} but not connected" | tee $logpath/swsan_${fabricname}_unused.csv
echo "TH;4;TAG;alias;number of defined zones;zone name" | tee -a $logpath/swsan_${fabricname}_unused.csv
sed '1d' $logpath/san_result.csv | grep ";Online;" | rev | cut -d';' -f2 | rev | sed 's/(no_alias)//' | sed 's/(multiples_alias)//' | sed '/^$/d' | grep -v "(ISL)" | tr ' ' '\n' | sed 's/$/;/' > $logpath/saesult1.csv
for alias in $(cat $filename | grep '^alias' | cut -d'.' -f2- | cut -d':' -f1 | sort | uniq)
do
nb_zone=0
if [ $(grep "^${alias};" $logpath/san_result1.csv > /dev/null 2>&1;echo $?) -ne 0 ]
then
# Alias no more in use
cat $filename | grep "^zone." | sed 's/:/:;/' | sed 's/$/;/' | grep ";${alias};" | cut -d':' -f1 | cut -d'.' -f2 > $logpath/san_result2.csv
if [ -z $logpath/san_result2.csv ]
then
nb_zone=0
else
nb_zone=$(cat $logpath/san_result2.csv | tr -s ' ' '/n' | wc -l | awk '{print $1}')
fi
if [ "$nb_zone" == "0" ]
then
NAGIOSTAG=3
else
NAGIOSTAG=0
fi
prefix="TD;$NAGIOSTAG;$TAG"
echo "${prefix};$alias;$nb_zone;"$(cat $logpath/san_result2.csv) | tee -a $logpath/swsan_${fabricname}_unused.csv
else
echo ${alias} >> $logpath/swsan_good.txt
fi
done
done
}
#----------------------------
list_zones ()
{
echo "====== ZONING ======"
echo
echo "Generated from "$(hostname -s) $(date "+%d-%m-%Y %H:%M")
for fabricname in $(echo $allfabric)
do
filename=$(ls $logpath/swsan_${fabricname}_configshow_*.csv | head -1)
echo
echo "===== Zones defined on fabric ${fabricname} ====="
echo
cat $filename | grep '^zone.' | cut -d'.' -f2- | sed 's/:/\ /' | sed 's/$/\\/' | sed 's/$/\\/'
done
for fabricname in $(echo $allfabric)
do
filename=$(ls $logpath/swsan_${fabricname}_configshow_*.csv | head -1)
echo
cfg=$(cat $filename | grep '^enable:' | cut -d':' -f2)
zoning_active=$(grep "^cfg.${cfg}:" $filename | cut -d':' -f2- | sed -e 's/^/;/' -e 's/$/;/')
echo "===== Inactives zone in Fabric ${fabricname} ====="
echo
for zone in $(cat $filename | grep '^zone.' | cut -d'.' -f2- | awk -F':' '{print $1}')
do
if [ $(echo $zoning_active | grep ";${zone};" > /dev/null;echo $?) -ne 0 ]
then
echo "${zone}" | sed 's/$/\\/' | sed 's/$/\\/'
fi
done
done
for fabricname in $(echo $allfabric)
do
filename=$(ls $logpath/swsan_${fabricname}_configshow_*.csv | head -1)
echo
echo "===== Active configuration for fabric ${fabricname} ====="
echo
cfg=$(cat $filename | grep '^enable:' | cut -d':' -f2)
echo ${cfg}
echo
echo "==== Active zones ===="
echo
grep "^cfg.${cfg}:" $filename | cut -d':' -f2- | sed 's/;/\ /g' | sed 's/$/\\/' | sed 's/$/\\/'
done
}
#----------------------------
convert_html ()
{
#
# Voici le titre du tableau
# Titre A1 Titre A2 Titre A3 Titre A4
# Titre B1 Valeur B2 Valeur B3 Valeur B4
# Titre B1 Valeur B2 Valeur B3 Valeur B4
#
server=$(/bin/hostname -s)
echo '
SAN SWITCH CONFIG (generated from' $server')' $(date "+%d-%m-%Y %H:%M") '
SWITCHSHOW
'
for filename in $(ls $logpath/swsan_*_switchshow_*.csv)
do
nb_line=$(cat $filename | wc -l)
if [ "$nb_line" -gt "1" ]
then
fabricname=$(echo $filename | rev | cut -d'/' -f1 | cut -d'.' -f2 | rev | sed -e 's/swsan_/\ /' -e 's/_switchshow_/\ /' | awk '{print $1}')
switchname=$(echo $filename | rev | cut -d'/' -f1 | cut -d'.' -f2 | rev | sed -e 's/swsan_/\ /' -e 's/_switchshow_/\ /'| awk '{print $2}')
#echo 'Fabric: '$(echo $fabricname)' Switchname: '$(echo $switchname)'
'
cat $filename | grep '^H3' | sed -e 's/^H3;0;TAG;/\/' -e 's/$/\<\/h3\>\
/'
cat $filename | grep -v '^H3' > $TMPFILE.tempo
for nb in 0 1 2 3 4 5 6 7 8 9
do
for begin in TH TD
do
cat $TMPFILE.tempo | sed "s/^$begin;$nb;TAG;/\/g" > $TMPFILE.tempo1
mv $TMPFILE.tempo1 $TMPFILE.tempo
done
done
cat $TMPFILE.tempo | sed 's/;/<\/TD> /g' | sed 's/|/\ /g' | sed 's/$/<\/TD><\/TR>/g'
echo '
'
fi
done
echo '
'
}
#----------------------------
convert_html_unused ()
{
#
# Voici le titre du tableau
# Titre A1 Titre A2 Titre A3 Titre A4
# Titre B1 Valeur B2 Valeur B3 Valeur B4
# Titre B1 Valeur B2 Valeur B3 Valeur B4
#
server=$(/bin/hostname -s)
echo '
SAN SWITCH UNUSED ports (generated from' $server')' $(date "+%d-%m-%Y %H:%M") '
ALIAS
'
for filename in $(ls $logpath/swsan_*_unused.csv)
do
nb_line=$(cat $filename | wc -l)
if [ "$nb_line" -gt "1" ]
then
cat $filename | grep '^H3' | sed -e 's/^H3;0;TAG;/\/' -e 's/$/\<\/h3\>\
/'
cat $filename | grep -v '^H3' > $TMPFILE.tempo
for nb in 0 1 2 3 4 5 6 7 8 9
do
for begin in TH TD
do
cat $TMPFILE.tempo | sed "s/^$begin;$nb;TAG;/\/g" > $TMPFILE.tempo1
mv $TMPFILE.tempo1 $TMPFILE.tempo
done
done
cat $TMPFILE.tempo | sed 's/;/<\/TD> /g' | sed 's/|/\ /g' | sed 's/$/<\/TD><\/TR>/g'
echo '
'
fi
done
echo '
'
}
#------------------------------------------------
send_wiki()
{
dokupath=/var/www/html/archives/inventory/san
dokuuser=apache
dokugrp=apache
for file1 in san_switchshow.html san_unused_alias.html san_full_config.txt
do
sudo su - root -c "/bin/cp $logpath/$file1 $dokupath"
done
sudo su - root -c "/bin/chown -R $dokuuser.$dokugrp $dokupath"
# Archive
if [ ! -e $archpath/san_switchshow.html ]
then
for file1 in san_switchshow.html san_unused_alias.html san_full_config.txt
do
cp $logpath/$file1 $archpath
done
fi
}
#############################
# Main
#############################
main ()
{
date
echo "***** initialize"
initialize
echo "***** Switchshow"
list_switch_ports
echo "***** Sfpshow"
#list_switch_ports_signal
echo "***** convert HTML"
convert_html > $logpath/san_switchshow.html
echo "***** List Unused"
alias_unused > $logpath/san_unused_alias.csv
echo "***** convert HTML"
convert_html_unused > $logpath/san_unused_alias.html
echo "***** List FULL config"
list_zones > $logpath/san_full_config.txt
echo "***** Send to Wiki"
send_wiki
date
}
main > $logname 2>&1
===== Backup Brocade SAN switch =====
==== With standard user ====
[root@mgmt01 san]# cat backup_brocade_config.sh
#!/bin/bash
#set -x
#====================================================================
#@(#) Script to backup SAN switches
#====================================================================
# version 1.0 eif
dir=`dirname $0`
. $dir/.env
os=$(uname -s | tr 'A-Z' 'a-z')
USER=report
listswitch="san01 san02" # All SAN switches from all fabric separated by space
month=$(date "+%Y-%m")
archpath=/workdir/san/backup/$month
#----------------------------
initialize ()
{
echo "# Initialize"
mkdir -p $archpath > /dev/null 2>&1
}
#----------------------------
backup_san_switches ()
{
fabric=fabric
for sw in $listswitch
do
echo "######## $sw"
ssh $USER@$sw "configshow -all" > $archpath/${sw}.txt
done
}
#############################
# Main
#############################
main ()
{
date
echo "***** initialize"
initialize
echo "***** Backup SAN switches"
backup_san_switches
date
}
main > $logname 2>&1
==== With privileged user ====
[root@mgmt01 san]# cat backup_brocade_switches.sh
#!/bin/ksh
# Script to back up SAN configuration using ssh and scp.
# Variable declaration
RC=0
SUMRC=0
SAN_LIST="SAN_SW1 SAN_SW2 SAN_SW3"
BCKSRV="IP_OF_BACKUP_SERVER|"
BCK_DIRECTORY="/directory/where/to/backup"
BCK_USER=BACKUP_SERVER_USER
#TODAY=`date +"%Y%m%d"`
for san in $SAN_LIST
do
echo "Backing up SAN switch config data..." $san
ssh admin@$san "configupload -all -p sftp $BCKSRV,$BCK_USER,$BCK_DIRECTORY/$san.cfg"
RC=$?
echo "RC = " $RC
SUMRC=$((SUMRC+RC))
done
#TSM backup
echo "Archiving configuration of all SAN switches..."
dsmc archive "$BCK_DIRECTORY/*" -archmc=MC_NAME
RC=$?
echo "RC = " $RC
SUMRC=$((SUMRC+RC))
exit $SUMRC
===== dev =====
list all Virtual FID
$ ssh usr1@san1 'lscfg --show' | grep '^FID' | sed 's/FID//' | tr '|' '\n' | awk '{print $1}' | sed '/^$/d' | sort -u
Example of commands on vFID
$ fosexec --fid 10 -cmd "switchshow"
===== List errors on ports =====
List error count\\
**check_porterrshow.sh**
#!/bin/bash
#set -x
#
#@(#) Send error on SAN switches ports
#
# version: 1.0 2014
# version: 1.1 02-2020 Manu
#
dir=`dirname $0`
. $dir/.env
# Variables
destination="bp.san@test.lu"
#destination="myemail@test.lu"
user_repoting="readonly"
SSH="ssh -o ConnectTimeout=10 -o ConnectionAttempts=1 -o BatchMode=yes ${user_repoting}@"
logfile=$logpath/porterrshow.txt
errfile=$logpath/porterrshow.err
list=$dir/sansw_list.txt
server=$(hostname -s)
# clear log
if [[ -f $logfile ]]
then
rm $logfile > /dev/null 2>&1
fi
if [[ -f $errfile ]]
then
rm $errfile > /dev/null 2>&1
fi
#----------------------
get_fids ()
{
for sw in $(cat $list)
do
echo "######## $sw ########"
${SSH}$sw 'lscfg --show' > $logfile
if [ "$?" -ne "0" ]
then
echo "Connection error on san switch: ${SSH}$sw" >> $errfile
fi
fids=$(cat $logfile | grep '|' | sed 's/^\ //' | cut -d' ' -f2- | sed 's/|/\ /g' | tr -s ' ' | tr ' ' '\n' | sort -u | sed '/^$/d' | tr '\n' ' ')
echo "FID : $fids"
done
### fosexec --fid 2 -cmd "switchshow"
}
#----------------------
porterrshow ()
{
echo "====== Porterrshow on SAN switches (generated from $server) "$(date "+%d-%m-%Y %H:%M")" ======" > $logfile
echo >> $logfile
for sw in $(cat $list)
do
echo "######## $sw ########"
echo "===== $sw =====" >> $logfile
${SSH}$sw "porterrshow" > $logfile.1
cat $logfile.1 | tr '\t' ' ' | sed 's/\ /;/g' | tr -s ';' | grep -v ';0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;' | sed 's/^;frames;/index;frames;frames;/' | sed 's/;c3timeout;/;c3timeout;c3timeout;/' | sed 's/^;tx;/index;tx;/' | sed 's/;sig;tx;/;sig;\ ;\ ;tx;/' | sed 's/^;//' | rev | sed 's/^;//' | rev | sed 's/^/;/' | sed 's/$/;/' | sed '/^;index;/s/;/^/g' | sed 's/;/|/g' >> $logfile
echo >> $logfile
done
}
#----------------------
sendemail ()
{
if [[ -s $errfile ]]
then
cat $errfile | mailx -s "Connection error Porterrshow SAN" $destination
fi
}
#----------------------
send_wiki ()
{
dokupath=/var/www/html/archives/inventory/san
dokuuser=apache
dokugrp=apache
for file1 in $logfile
do
sudo su - root -c "/bin/cp $file1 $dokupath"
done
sudo su - root -c "/bin/chown -R $dokuuser.$dokugrp $dokupath"
}
#########################
# Main
#########################
main ()
{
date
echo "FIDs"
get_fids
echo "porterrshow"
porterrshow
echo "sendemail"
sendemail
echo "Add to wiki"
send_wiki
}
main > $logname 2>&1