【发布时间】:2017-06-03 01:53:54
【问题描述】:
我正在尝试在 bash 脚本中执行一个期望脚本,但是当我尝试在没有“| tee -a xxx.log”的情况下执行 shell 时(其中 xxx.log 是一个文件,而不是我想要写入来记录 ssh 会话)。
这段代码运行良好:
comlog="ssh $USR@192.168.228.20"
expect -c"
spawn \"$comlog\"
expect \"Password:\"
send \"$PASS\r\"
interact
"
但是当我尝试添加“tee -a”命令来保存 ssh 会话时,问题是
invalid command name "ssh"
while executing
这是我获取错误消息的完整命令
comlog="ssh $USR@192.168.228.20 | tee -a /home/xxx.log"
expect -c"
spawn \"$comlog\"
expect \"Password:\"
send \"$PASS\r\" #Already Obteined
interact
"
我尝试以这种方式更改“comlog”变量,但不起作用:(
cssh $USR@192.168.228.20 \| tee -a /home/xxx.log
有谁知道另一种保存从expect 开始的ssh 会话的方法?或者我怎样才能在同一个 spawn 命令中发送这两个命令。
【问题讨论】:
-
您是否探索过设置公钥身份验证以避免使用
expect? -
因为我是系统管理员来生成该服务器的公钥:(我需要经常连接到该服务器
标签: linux bash shell ssh expect