Read file into String and do a loop in Expect Script

前端 未结 3 1526
萌比男神i
萌比男神i 2020-12-05 12:30

What I am trying to do is to:

  1. Create a .exp file, which will read from the *.txt file from the same directory and parse all the conte
3条回答
  •  再見小時候
    2020-12-05 13:10

    I'd refactor a bit:

    #!/usr/bin/expect
    
    set timeout 20
    set user test
    set password test
    
    proc check_host {hostname} {
        global user passwordt
    
        spawn ssh $user@$hostname
        expect "password"
        send "$password\r"
        expect "% "                ;# adjust to suit the prompt accordingly
        send "some command\r"
        expect "% "                ;# adjust to suit the prompt accordingly
        send "exit\r"
        expect eof
    }
    
    set fp [open commands.txt r]
    while {[gets $fp line] != -1} {
        check_host $line
    }
    close $fp
    

提交回复
热议问题