2017-03-09 7 views
0

複数のciscoスイッチのスイッチ設定の変更を自動化しようとしています。私はconfigセクションに移動し、config.txt変数を送信すると、最後に中括弧が付き、有効なコマンドではありません。ここに出力があり、その下にコードを掲載します。 私がやろうとしていますすべては私のスイッチにログインし、交換する次のコマンド configureを実行したフラッシュ:/ thenameofconfig スクリプトは、デバイスリスト内の複数のスイッチをループとはexpect言語を使用したコマンド入力の波括弧

IL-テストO系、正しい設定を適用します/ IL-テスト-SW2-confgファイル} {}

コード:-SW1#1 configureがフラッシュが代わる

#!/usr/bin/expect -f 

# Set up various other variables here ($user, $password) 
set username user 
set password user 
set enablepassword user 

# Log results 
#log_file -a ~/results.log 
log_file -a /tmp/results.log 







# Get the list of hosts, one per line ##### 
set f [open "device-list.txt"] 
set hostname [split [read $f] "\n"] 
close $f 

# Get the commands to run, one per line 
set f [open "configs.txt"] 
set configs [split [read $f] "\n"] 
close $f 

# Iterate over the hosts 
foreach host $hostname { 
# Don't check keys 
spawn ssh -o StrictHostKeyChecking=no $username\@$hostname 
# spawn ssh [email protected] 
# expect "password:" 
# send "$password\r" 
# Allow this script to handle ssh connection issues 
expect { 
timeout { send_user "\nTimeout Exceeded - Check Host\n"; exit 1 } 
eof { send_user "\nSSH Connection To $hostname Failed\n"; exit 1 } 
"*#" {} 
"*assword:" { 
send "$password\n" 
} 
} 

# If we're not already in enable mode, get us there 
expect { 
default { send_user "\nEnable Mode Failed - Check Password\n"; exit 1 } 
"*#" {} 
"*>" { 
send "enable\n" 
expect "*assword" 
send "$enablepassword\n" 
expect "*#" 
} 
} 

# Let's go to configure mode 
send "conf t\n" 
expect "(config)#" 
send "shell processing full\n" 
expect "(config)#" 
send "end\n" 
expect "*#" 

#Iterate over the commands 
foreach config $configs { 
expect "*#" 
send "$configs\n" 
expect "\[no]:" 
send "y\n" 
expect "*#" 
}  
    # Tidy up 
# expect "*#" 
# send "exit\r" 
# expect eof 
# close 
send "exit\n" 
expect ":~\$" 
exit 

} 

コマンドを置き換えるのconfigureの最後に{}を取り除くように見えることはできません。

ご協力いただきますようお願い申し上げます。

答えて

0

であることを

ニーズを[[] "\ n" を$ Fを読み、分割]次の行

セットのホスト名ました: セットのホスト名[分割[] "\ n" を-nonewline $ Fを読む]

関連する問題