期望脚本收集文件中的输出

时间:2022-11-02 13:53:14

I have following expect script, its running /tmp/find_users.sh script on remote host and i am trying to collect output of that script.

我有以下expect脚本,它在远程主机上运行/tmp/find_users.sh脚本,我正在尝试收集该脚本的输出。

#!/usr/bin/expect

set timeout 3
if {[llength $argv] != 1} {
    puts "usage: ssh-auto host"
    exit 1
}

set host  [lindex $argv 0]
spawn ssh -t -q -oStrictHostKeyChecking=no $host
expect "passphrase"
send "XXXXXXX\r"
expect "$"
send  "/tmp/find_users.sh\r"
expect eof

I am using following method to collect output of script.

我使用以下方法来收集脚本的输出。

./auto-ssh.ex servername > command_output.txt

Problem is in output its appending server prompt and banner other craps.. I want neat output not crap.. I am sure there is a good way but i don't know how.

问题是输出它的附加服务器提示和横幅其他掷骰子..我想整洁的输出而不是废话..我相信有一个好方法,但我不知道如何。

1 个解决方案

#1


1  

You can edit your remote shell to add log output to a file. And at the end of your expect script to get the log file using auto_scp.

您可以编辑远程shell以将日志输出添加到文件。在您的expect脚本结束时使用auto_scp获取日志文件。

#1


1  

You can edit your remote shell to add log output to a file. And at the end of your expect script to get the log file using auto_scp.

您可以编辑远程shell以将日志输出添加到文件。在您的expect脚本结束时使用auto_scp获取日志文件。