I created a bash function to "automagically" connect on our switches and retrive their startup-config using the expect command. I have to use expect because this switch does not accept the ssh user@host fashion and ask me again for the User and Password tuple.
This is the function that i created to manage those backups
main_pc3548(){
/usr/bin/env expect <<-END3548
spawn ssh -o StrictHostKeyChecking=no -o LogLevel=quiet $IP
expect "User Name:"
send "$USER\r"
expect "Password:"
send "$PASS\r"
expect "*# "
send "copy startup-config tftp://$SERVER/$SWNAME.cfg.bkp\r"
sleep 8
END3548
}
This block of code will separate my switch types, and call main_pc3548() when my switch list have this switch model:
egrep -v '(^#|^\s*$|^\s*\t*#)' $LISTA_SWITCHES | while read IP SWNAME SERVER TIPO
do
if [ "$TIPO" = core ]; then
main_pc6248
elif [ "$TIPO" = dep ]; then
main_pc3548
else
echo "$(date "+%d/%m/%Y-%T") - Switch $SWNOME Have a martian type of switch" >> $LOG_FILE
fi
done
The rest of the script reads a pretty lengthy file with information about the Switch IP, the TFTP ip address, the Switch name, and waiting 8 seconds each switch consumes a lot of time. This sleep is needed to avoid slow connections to break the tftp copy so, here it comes my question:
Is there a easy way to "multithread" this function to gain performance?
main_pc6248 &andmain_pc3548 &did the trick