期望无法将cmd输出写入文件

时间:2019-06-01 12:48:58

标签: expect

ssh到palo alto设备,希望我能成功运行一些命令,但无法在bash中接收命令输出

#!/usr/bin/expect -f
set timeout -1
match_max 100000
set IPadress [lindex $argv 0]
set Username "user"
set Password "pass"
log_file -a ~/results.log
spawn ssh -o StrictHostKeyChecking=no -l $Username $IPadress
expect "Password:"
send -- "$Password\r"
sleep 10

expect "*>"
set output [open "outputfile.txt" "a+"]
send "set cli pager off \r"
sleep 10
expect "*>"
send "configure\r"
sleep 30
expect "*#"
send "show rulebase security rules\r"
sleep 20
expect "*#"
set outcome $expect_out(buffer)
puts $output $outcome
close $output
sleep 10
send "exit\r"

bash脚本

#!/bin/bash
set -x
for i in `cat list.txt`
do
ping -c 2  $i >/dev/null 2>&1;
if [ $? == 0 ]; then
echo "$i up and running" >> /home/user/uphost.txt
./pa2.sh $i
else
echo "$i is down"
fi
done

输出结果为:

[root@host]# cat outputfile.txt 
user@pa2(active)#

期望整个命令输出

0 个答案:

没有答案