【问题标题】:logging a telnet session as a background process将 telnet 会话记录为后台进程
【发布时间】:2014-09-30 20:58:02
【问题描述】:

我想要实现以下目标:我们有一个电信系统,它对所有传入和传出呼叫进行协议,并通过 telnet 实时访问数据。我想要做的是在与系统永久连接并记录数据的 Debian 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 命令中)。如何强制期望脚本留在后台? 提前致谢!

【问题讨论】:

    标签: bash background-process telnet expect


    【解决方案1】:

    试试“expect_background”。有关“http://linux.about.com/od/commands/a/The-Linux-Unix-Command-Expect_2.htm”的更多详细信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-05
      • 2019-09-11
      • 2023-02-07
      • 2013-04-04
      • 2014-01-13
      • 2016-09-25
      相关资源
      最近更新 更多