以期待的方式通过SCP更新IOS

美好的一天。 我试图创build/运行一个脚本,这将允许我从服务器发送更新的IOS到我的networking设备。 当我在“:flash”命令之前input一个手动IP地址时,下面的代码工作。

#!/user/bin/expect set IOSroot "/xxxxx/xxx/c3750e-universalk9-mz.150-2.SE10a.bin" set pw xxxxxxxxxxxxxxxxxxx spawn scp $IOSroot 1.1.1.1:flash:/c3750e-universalk9-mz.150-2.SE10a.bin expect "TACACS Password:" send "$pw\r" interact 

那里的代码很好,正如预期的那样。 当我尝试使用名为“ioshost”的IP列表的文件并在该脚本中使用该文件来获得一些自动化时,会出现问题。 我已经尝试了各种各样的事情来得到这个工作。 其中一些如下:

设置variables

 IPHosts=$(cat ioshost) set IPHost 'cat ioshost' 

随着试图使用读/做命令…

 while read line; do spawn scp $IOSroot $line:flash:/c3750e-universalk9-mz.150-2.SE10a.bin done < ioshost 

这些似乎都没有工作,我正在寻找指导。 请注意,我明白,设置密码不是最好的做法,但设置其他文章中提到的RSA密钥是不允许的,所以我被迫这样做。

感谢您的时间。

您可以使用一个Expect脚本和一个Bash脚本。

首先更新你的Expect脚本:

 #!/user/bin/expect set IOSroot "/xxxxx/xxx/c3750e-universalk9-mz.150-2.SE10a.bin" set pw xxxxxxxxxxxxxxxxxxx spawn scp $IOSroot [lindex $argv 0]:flash:/c3750e-universalk9-mz.150-2.SE10a.bin # ^^^^^^^^^^^^^^^^ expect "TACACS Password:" send "$pw\r" interact 

然后写一个简单的Bash for循环:

 for host in $(<ioshost); do expect /your/script.exp $host done 
Interesting Posts