#!/bin/bash
expect << EOF
exp_internal 1
spawn ssh nbhambha@10.118.137.78
expect "ssword:"
send "********\r"
sleep 3
set list [open list1 r]
foreach line \$list
{
expect " $"
send "seeisso \$list | grep -E -i ' os |proddropdown|hostname'"
send "\r"
sleep 5
expect -re " $"
set fid [open out1.txt a]
puts \$fid \$expect_out(buffer)
}
close $fid
EOF
======
清单 1 包含:
APSE0112
ETLLT0000
==============
脚本的结果:
expect: does " " (spawn_id exp6) match glob pattern " $"? yes
expect: set expect_out(0,string) " "
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) " "
send: sending "seeisso file7 | grep -E -i ' os |proddropdown|hostname'" to { exp6 }
send: sending "\r" to { exp6 }
expect: does "" (spawn_id exp6) match regular expression " $"? no
expect: does "\r\n" (spawn_id exp6) match regular expression " $"? no
seeisso file7 | grep -E -i ' os |proddropdown|hostname'
expect: does "\r\nseeisso file7 | grep -E -i ' os |proddropdown|hostname'\r\n" (spawn_id exp6) match regular expression " $"? no
====================
我不知道它从哪里获取 file7 值。当我改变时:
send "seeisso \$list | grep -E -i ' os |proddropdown|hostname'"
至
send "seeisso **$list** | grep -E -i ' os |proddropdown|hostname'"
它需要一个空值:
expect: set expect_out(0,string) " "
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) " "
send: sending "seeisso | grep -E -i ' os |proddropdown|hostname'" to { exp6 }
send: sending "\r" to { exp6 }
expect: does "" (spawn_id exp6) match regular expression " $"? no
expect: does "\r\n" (spawn_id exp6) match regular expression " $"? no
seeisso | grep -E -i ' os |proddropdown|hostname'
===========
请帮忙