美好的一天。 我正在尝试创建/运行一个脚本,允许我将更新的IOS从服务器发送到我的网络设备。 当我在“:flash”命令之前输入手动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列表并在此脚本中使用它来获得一些自动化时,会出现问题。 我尝试过各种各样的东西让它发挥作用。 其中一些如下:
设置变量
IPHosts=$(cat ioshost) set IPHost 'cat ioshost'一起尝试使用read / do命令......
while read line; do spawn scp $IOSroot $line:flash:/c3750e-universalk9-mz.150-2.SE10a.bin done < ioshost这些似乎都不起作用,我正在寻找指导。 请注意我明白设置密码不是最佳做法,但不允许设置其他文章中提到的RSA密钥,所以我不得不这样做。
感谢您的时间。
Good day. I am attempting to create/run a script that will allow me to send an updated IOS from a server to my network devices. The following code works when I put in a manual IP address right before the ":flash" command.
#!/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" interactThe code there works great and as expected. The issue arises when I try to use a file called "ioshost" with a list of IP's and use that within this script to get some automation. I have tried various things to get this to work. Some of them are as follows:
Settings Variables
IPHosts=$(cat ioshost) set IPHost 'cat ioshost'Along with trying to use the read/do command...
while read line; do spawn scp $IOSroot $line:flash:/c3750e-universalk9-mz.150-2.SE10a.bin done < ioshostNone of these seem to work and I am looking for guidance. Please note I understand that setting a password is not best practice but setting RSA keys as mentioned in other articles is not allowed so I am forced to do it this way.
Thank you for your time.
最满意答案
您可以使用一个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 doneYou can use one Expect script and one Bash script.
First update your Expect script a bit:
#!/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" interactThen write a simple Bash for loop:
for host in $(<ioshost); do expect /your/script.exp $host done更多推荐
发布评论