#!/bin/bash
USERNAME=用户名
PASSWORD=交换机密码
COUNT=cat ip | wc -l
DIR=/root/shell/passwd/date +%Y%m%d
if [ ! -d $DIR ];then
mkdir -p $DIR
echo -e "\033[32m This is $DIR mkdir success\033[0m"
for ((i=1;i<=${COUNT};i++))
do
expect << EOF | tee -a $DIR/cat ip | awk '{print $2}' | sed -n "${i}p"
.log
set timeout 30
spawn ssh -q network@cat ip | awk '{print $1}' | sed -n "${i}p"
expect {
“yes/no”
{ send “yes\r”;exp_continue}
“Password:”
{ send “KaTeX parse error: Can't use function '\r' in math mode at position 9: PASSWORD\̲r̲"} } exp…PASSWORD\r” }
}
expect {
“aaa]"
{ send “quit\r” }
}
expect {
"]”
{ send “quit\r” }
}
expect {
“>"
{ send “save\r” }
}
expect {
"]”
{ send “y\r” }
}
expect {
“>"
{ send “dis history-command\r” }
}
expect {
">”
{ send “quit\r” }
}
expect eof
EOF
if [ $? = 0 ];then
echo “switch backup sucess ip:cat ip | awk '{print $1}' | sed -n "${i}p"
name:cat ip | awk '{print $2}' | sed -n "${i}p"
” >> $DIR/sucess.txt
echo -e “\033[32m cat ip | awk '{print $2}' | sed -n "${i}p"
backup sucess\033[0m”
else
echo “switch backup failed ip:cat ip | awk '{print $1}' | sed -n "${i}p"
name:cat ip | awk '{print $2}' | sed -n "${i}p"
” >> $DIR/failed.txt
echo -e “\033[32m cat ip | awk '{print $2}' | sed -n "${i}p"
backup failed\033[0m”
fi
done
else
for ((i=1;i<=${COUNT};i++))
do
expect << EOF | tee -a $DIR/cat ip | awk '{print $2}' | sed -n "${i}p"
.log
set timeout 30
spawn ssh -q network@cat ip | awk '{print $1}' | sed -n "${i}p"
expect {
“yes/no”
{ send “yes\r”;exp_continue}
“Password:”
{ send “KaTeX parse error: Can't use function '\r' in math mode at position 9: PASSWORD\̲r̲"} } exp…PASSWORD\r” }
}
expect {
“aaa]"
{ send “quit\r” }
}
expect {
"]”
{ send “quit\r” }
}
expect {
“>"
{ send “save\r” }
}
expect {
"]”
{ send “y\r” }
}
expect {
“>"
{ send “dis history-command\r” }
}
expect {
">”
{ send “quit\r” }
}
expect eof
EOF
if [ $? = 0 ];then
echo “switch backup sucess ip:cat ip | awk '{print $1}' | sed -n "${i}p"
name:cat ip | awk '{print $2}' | sed -n "${i}p"
” >> $DIR/sucess.txt
echo -e “\033[32m cat ip | awk '{print $2}' | sed -n "${i}p"
backup sucess\033[0m”
else
echo “switch backup failed ip:cat ip | awk '{print $1}' | sed -n "${i}p"
name:cat ip | awk '{print $2}' | sed -n "${i}p"
” >> $DIR/failed.txt
echo -e “\033[32m cat ip | awk '{print $2}' | sed -n "${i}p"
backup failed\033[0m”
fi
done
fi