0
我有一個包含服務器(空間)的用戶列表的文件,現在我想將這個文件作爲參數傳遞給我的期望腳本,這樣我的腳本將產生一個ssh會話用戶@服務器,並執行了一堆命令和退出。如何傳遞多個參數從文件的foreach
cat HostsUserFile.txt
Server1 User1
Server2 User2
Server3 User3
cat CollectStats.exp
### Get the list of hosts, one per line, whereas hosts.txt should be a file containing the list of servers and user #####
set password ****
set f [open "HostsUserFile.txt"]
set hosts [split [read -nonewline $f] "\n"]
close $f
### Loop through the hosts listed in host.txt ###
foreach { host user } $hosts {
### spawn ssh process ###
spawn -noecho ssh -q [email protected]$host -o StrictHostKeyChecking=no
expect "*?assword*"
send "$password\r"
expect "*$*"
send "exit\r"
}
我想在第一次迭代期間將Server1替換爲主機並將User1替換爲用戶變量等等。
請幫我實現這一目標。謝謝。
什麼你試過這麼遠嗎? –