我正在尝试使用expect脚本登录虚拟机(VM)后安装rpm包。 日志记录很好但是在尝试运行rpm命令时它正从VM退出并返回到被叫机器。 该命令调用rpm安装 rpm -ivh --force pkg_name
使用expect登录即可使用 产生ssh root@1.1.1.1然后当它需要我发送的密码时。
有人遇到过这样的问题吗? 任何帮助都会有用。 谢谢。
以下是登录系统的expect文件 login_script.exp
#!/usr/bin/expect
set timeout 60
set prompt {[#>$] }
system "rm -f ~/.ssh/known_hosts"
spawn ssh root@1.1.1.1
expect {
"yes/no" {
send "yes\r"
expect {
"*?assword: " {
send "abcdefgh\r"
expect -re $prompt {}
}
}
}
"*?assword" {
send "abcdefgh\r"
expect -re $prompt {}
}
}
send "sleep 1\r"
send "sudo -i\r"
expect "*?assword" { send "abcdefgh\r" }
原始脚本将调用
/usr/bin/expect << -EOF-
source login_script.exp
expect "\$prompt" ;# wait for prompt
send "rpm -ivh --force /tmp/pkg_abc\r"
expect "\$prompt" ;# wait for prompt
-EOF-
两者的输出:
[根@
YYY-BServer01 ~]# rpm -ivvh --force /tmp/pkg_abc
D: ============== /tmp/pkg_abc
D: loading keyring from pubkeys in /var/lib/rpm/pubkeys/*.key
D: couldn't find any keys in /var/lib/rpm/pubkeys/*.key
D: loading keyring from rpmdb
D: opening db environment /var/lib/rpm cdb:0x401
D: opening db index /var/lib/rpm/Packages 0x400 mode=0x0
D: locked db index /var/lib/rpm/Packages
D: opening db index /var/lib/rpm/Name 0x400 mode=0x0
D: read h#
622标题健全性检查:OK-bash-4.1#