1

ネットワークデバイス構成(Ciscoデバイス)をバックアップするために、Exepct言語で次のサンプルスクリプトを実行しました

#!/usr/bin/expect -f

# ---------------- configuration ---------------- #

set device 192.168.244.20   
set user go00080         
set pass password        
set tftp 192.168.244.243              
set timeout 60

# -------------- core -------------- #
spawn telnet $device
expect "Username:"
send "$user\n"
expect "Password:"
send "$pass\n"
send "copy running-config tftp://192.168.244.243\r"
expect "Address or name of remote host"
send "\r"
expect "Destination filename "
send "\r"
expect "secs"
send "exit\r"
close
exit 0

ここで、スクリプトがcsvから$ deviceをロードするか、txtファイルからより単純にロードするようにします。つまり、私のtxtファイルに次のようにすべてのciscoipアドレスが含まれているとします。

192.168.244.20
192.158.244.21
...
192.168.244.245

そのスクリプトがtxtファイルをロードしたら、毎回1つのIPアドレスをロードし、そのIPアドレスを$ device変数に割り当ててから、コマンド「copyrunning-config ...」を作成します。どうすればよいですか?誰でも私を助けることができます

4

1 に答える 1

4
# -------------- core -------------- #
set file_handle [open text.txt r]
while {[gets $file_handle device] != -1} {
    spawn telnet $device
    #... same as above
    send "exit\r"
    expect eof
}
close $file_handle

特定のコマンドのヘルプについては、http://tcl.tk/man/tcl8.5/TclCmd/contents.htmを参照してください。

于 2012-06-07T11:28:27.113 に答える