- 论坛徽章:
- 0
|
回复 6# waker
好像有点儿小问题,请教下:
#! /bin/sh
expect <<EOF
spawn ssh root@172.16.217.129 "test -f /root/.ssh/id_rsa||echo xxxxxxxxxxxxxooooooooooo"
expect {
"password:" {
send "123456\n";exp_continue
}
}
expect xxxxxxxxxxxxxooooooooooo { exit 55 }
EOF
if [ $? -eq 55 ];then
echo "File not exist"
else
echo "File exist"
fi
我用expect -d跟踪的结果如下:
expect version 5.43.0
argv[0] = expect argv[1] = -d
set argc 0
set argv0 "expect"
set argv ""
executing commands from command file
spawn ssh root@172.16.217.129 test -f /root/.ssh/id_rsa||echo xxxxxxxxxxxxxooooooooooo
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {7217}
expect: does "" (spawn_id exp6) match glob pattern "password:"? no
root@172.16.217.129's password:
expect: does "root@172.16.217.129's password: " (spawn_id exp6) match glob pattern "password:"? yes
expect: set expect_out(0,string) "password:"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "root@172.16.217.129's password:"
send: sending "123456\n" to { exp6 }
expect: continuing expect
expect: does " " (spawn_id exp6) match glob pattern "password:"? no
expect: does " \r\n" (spawn_id exp6) match glob pattern "password:"? no
expect: read eof
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) " \r\n"
expect: spawn id exp6 not open
while executing
"expect xxxxxxxxxxxxxooooooooooo { exit 55 } "
File exist
|
|