将telnet会话记录为后台进程

时间:2014-08-07 14:48:28

标签: bash background-process telnet expect

我想实现以下目标:我们有一个电信系统,可以协调所有传入和传出呼叫,并通过telnet实现数据的实时访问。我想要做的是在Debian VM上运行后台脚本,该VM与系统永久连接并记录数据。 经过一些研究(我对shell脚本非常不熟悉),我决定使用工具脚本并期待。 记录部分到目前为止工作;背景部分不太好。我告诉你到目前为止我的两个脚本:

#!/bin/bash
script -f -q -c"./autotelnet.sh 192.168.xxx.xxx mylogin mypassword" -a output.log &

这是自动telnet连接的脚本:

#!/usr/bin/expect -f
#autotelnet.sh
set timeout 20
set name [lindex $argv 0]
set port [lindex $argv 1]
set user [lindex $argv 2]
set password [lindex $argv 3]
spawn telnet $name $port
expect "Escape character is '^]'.-" #This is the actual login name prompt. 
send "$user\r"
expect "Password:"
send "$password\r"
interact

现在,如果我只输入“./telefonlog&”尽管第一个脚本中有&符号,但它不会在后台启动,但所有内容都会按原样记录。 (顺便说一下,在telnet会话中我无法将CTRL-Z转换为bg命令工作)。如何强制期望脚本留在后台? 在此先感谢!

1 个答案:

答案 0 :(得分:1)

尝试" expect_background"。关于" http://linux.about.com/od/commands/a/The-Linux-Unix-Command-Expect_2.htm"。

的更多细节