![예상되는 스크립트 버퍼 출력이 표시되지 않음](https://linux55.com/image/35124/%EC%98%88%EC%83%81%EB%90%98%EB%8A%94%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%20%EB%B2%84%ED%8D%BC%20%EC%B6%9C%EB%A0%A5%EC%9D%B4%20%ED%91%9C%EC%8B%9C%EB%90%98%EC%A7%80%20%EC%95%8A%EC%9D%8C.png)
버퍼에서 명령 출력을 얻는 방법은 무엇입니까? 현재는 "(버퍼)라고만 표시됩니다.
내 스크립트 및 디버그 출력은 다음과 같습니다.
#!/bin/bash -x
while read p; do
echo $p
{
/usr/bin/expect -d << EOF
match_max 10000
spawn ssh anthony@$p
expect "password:"
send "MyPasswordHere\r"
expect " "
send "ifconfig |grep -i eth0\r"
expect " "
puts "The output is $expect_out(buffer) "
send "exit\r"
EOF
}
done <List.txt
+ read p
+ echo localhost
localhost
+ /usr/bin/expect -d
expect version 5.45
argv[0] = /usr/bin/expect argv[1] = -d
set argc 0
set argv0 "/usr/bin/expect"
set argv ""
executing commands from command file
spawn ssh anthony@localhost
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {2032}
expect: does "" (spawn_id exp15) match glob pattern "password:"? no
anthony@localhost's password:
expect: does "anthony@localhost's password: " (spawn_id exp15) match glob pattern "password:"? yes
expect: set expect_out(0,string) "password:"
expect: set expect_out(spawn_id) "exp15"
expect: set expect_out(buffer) "anthony@localhost's password:"
send: sending "M00nsh0t@\r" to { exp15 }
expect: does " " (spawn_id exp15) match glob pattern " "? yes
expect: set expect_out(0,string) " "
expect: set expect_out(spawn_id) "exp15"
expect: set expect_out(buffer) " "
send: sending "ifconfig |grep -i eth0\r" to { exp15 }
expect: does "" (spawn_id exp15) match glob pattern " "? no
expect: does "\r\n" (spawn_id exp15) match glob pattern " "? no
Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-40-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Sun Dec 21 09:23:38 2014 from localhost
expect: does "\r\nWelcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-40-generic x86_64)\r\n\r\n * Documentation: https://help.ubuntu.com/\r\n\r\nLast login: Sun Dec 21 09:23:38 2014 from localhost\r\r\n" (spawn_id exp15) match glob pattern " "? yes
expect: set expect_out(0,string) " "
expect: set expect_out(spawn_id) "exp15"
expect: set expect_out(buffer) "\r\nWelcome "
The output is (buffer)
send: sending "exit\r" to { exp15 }
+ read p
답변1
예상 스크립트는 따옴표가 없는 구분 기호로 되어 있으므로 예상 변수는 쉘 변수로 처리됩니다. 변화
puts "The output is $expect_out(buffer) "
도착하다
puts "The output is \$expect_out(buffer) "
표시되는 출력( The output is (buffer)
)은 정확히 내가 예상한 것과 같습니다. $expect_out
스크립트를 예상대로 전달하기 전에 쉘이 아무것도 확장되지 않았습니다.