1
#!/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'

===========

请帮忙

4

1 回答 1

2

我看到了几个问题:

  1. list在您的情况下,实际上是文件句柄,而不是文件的内容。
  2. 你以前有反斜杠$list,我不明白原因
  3. 你不使用你的line变量

这是一个建议,看看它是否有效:

set fileHandle [open list1]
while {[gets $fileHandle line] != -1} {
    expect " $"
    send "seeisso $line | grep -E -i ' os |proddropdown|hostname'"
    send "\r"
    # the rest ...
}
close $fileHandle
于 2013-04-24T16:52:40.310 回答