#!/bin/bash
mkdir /var/lib/tftpboot/h3c_`date +"%Y%m%d"`
path=/var/lib/tftpboot/h3c_`date +"%Y%m%d"`
while read line;do
fping $line > /dev/null
if [ $? -eq 0 ];then
expect ./loginsw.exp $line >>./expect.log
mv /var/lib/tftpboot/aaa.cfg $path/"$line".cfg
echo $line >> ./online-ip.log
else
echo $line >> ./offline-ip.log
fi
done < ./sw.txt
#!/usr/bin/expect
set ipaddr [lrange $argv 0 0]
set timeout 5
spawn telnet $ipaddr
expect "Username:"
send "ly\r"
expect "Password:"
send "ly123\r"
expect "*>"
send "system-view\r"
expect "*]"
send "local-user lytech\r"
expect "*]"
send "password cipher Dong\r"
expect "*]"
send "quit\r"
expect "*]"
send "quit\r"
expect "*>"
send "save\r"
expect "*:"
send "y\r"
expect "*):"
send "\r"
expect "*:"
send "y\r"
expect "*>"
set timeout -1
send "tftp 10.0.40.44 put startup.cfg aaa.cfg\r"
send "quit\r"
send "exit\r"
expect eof