Expect脚本失败解析主机名主机

时间:2016-04-18 07:30:01

标签: expect

我正在尝试运行以下期望的scriipt登录到多个主机并在这些主机上运行一些命令。 我有两个文件1)host.txt,其中包含主机名,另外2)commands.txt包含要执行的commans。 虽然,虽然我正在运行它通过我在下面给出的错误..请指教..我通过stackoverflow完成了所有的解决方案,但没有让事情工作..

SCRIPT CODE .....

$ cat myexpc
#!/usr/bin/expect -f
# Set up various other variables here ($user, $password)
set timeout 20
set user karn
set password 123
# Get the list of hosts, one per line #####
set f [open "host.txt"]
set hosts [split [read $f] "\n"]
close $f

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

# Iterate over the hosts
foreach host $hosts {
    spawn ssh $user@$host
    expect "password:"
    send "$password\r"

    # Iterate over the commands
    foreach cmd $commands {
        expect "% "
        send "$cmd\r"
    }

    # Tidy up
    expect "% "
    send "continue\r"
    expect eof
    close
}

====================

    SCRIPT RUN & FAILURE CODE ..........
    $ ./myexpc
    spawn ssh karn@Server1
The authenticity of host 'server1 (192.2.47.194)' can't be established.
RSA key fingerprint is 33:r3:31:dd:a1:8a:38:08:b7:b1:e1:24:bc:cd:e2:5c.
Are you sure you want to continue connecting (yes/no)? yes
123
Please type 'yes' or 'no': yes
/bin/grep  192.17.14.1 /etc/ldap.conf /etc/resolv.conf
Please type 'yes' or 'no': yes

y
y
y
y
y
y

它一直在运行

0 个答案:

没有答案