1,先设置交换机设置不分屏

user-interface vty 0 4

screen-length 0

 

2,编辑expect脚本

cat discu.exp

#!/usr/bin/expect

set timeout 10

spawn ssh -l admin 192.168.0.1

expect "password"

send "123456\r"

sleep 1

send "dis cu \r"

send "q \r"

expect eof

exit

 

3,加入crontab做定期配置保存:

30 23 * * 5  /root/tasks/expect.sh  > /root/tasks/discu.txt 2>&1