我试图在后台运行多个使用shell脚本的expect实例,但实际发生的情况是,当shell脚本甚至终止时在运行shell脚本并期望在后台运行脚本之后。下面是两个脚本 -在后台通过shell脚本运行多个expect实例来收集日志
shell脚本 - shell_script.sh
#!/bin/bash
echo "shell script"
expect expect_script.sh abc1.com user_id password >> /var/logs/abc1.log &
sleep 5
expect expect_script.sh abc2.com user_id password >> /var/logs/abc1.log &
Expect脚本 - expect_script.sh
#!/usr/bin/expect
set timeout 20
set ip [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]
spawn telnet $ip
expect "User Access Verification"
expect "Username:"
send "$user\r"
expect "Password:"
send "$password\r";
expect eof
我这是怎么执行 -
SH shell_script.sh &
此scrip的全部目的t是在后台运行期望脚本来收集日志,直到进程被终止。另一种选择是逐个运行每个expect脚本,但为了自动化并适应将来的请求,这些expect脚本必须使用shell脚本运行。
我不是这方面的专家,任何帮助都非常感谢。
非常感谢, Sirish。
所以你telnet到一个设备,然后等待eof。在连接关闭之前,空闲的telnet会话保持多久? –
那么,这个telnet会话永远不会关闭,直到进程被终止,这就是主机的配置方式。这些主机通过telnet端口发送数据,应该使用expect脚本将这些数据捕获到日志文件中。希望我很清楚。 – Sirish