What I am trying to do is to:
- Create a
.exp
file, which will read from the *.txt
file from the same directory and parse all the content in the text file into a string variable in the expect script.
- Loop the string, which contains a series of host names, and excecute a series of command until the string is enumerated.
So what the script does, is read a series of hostname from a txt
file in the same directory, and then read them into a string, and the .exp
file will auto log into each of them and excecute a series of commands.
I have the following code written but it's not working:
#!/usr/bin/expect
set timeout 20
set user test
set password test
set fp [open ./*.txt r]
set scp [read -nonewline $fp]
close $fp
spawn ssh $user@$host
expect "password"
send "$password
"
expect "host1"
send "$scp
"
expect "host1"
send "exit
"
Any help is greatly appreciated....
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…