- 论坛徽章:
- 2
|
我想通过expect 远程登陆,获取进程PID,然后把PID存到变量里,并打印出来。- #!/usr/bin/expect
- if { [llength $argv] == 0 } {
- send "Usage: a.exp host password\n"
- exit
- }
- #exp_internal 1
- set timeout -1
- set host [lindex $argv 0]
- set passwd [lindex $argv 1]
- set pid ""
- set process [lindex $argv 2]
- spawn ssh root@$host
- expect {
- "yes/no" {send "yes\r";exp_continue}
- "password:" {send "$passwd\r"}
- }
- expect "*#"
- send -- "ps aux | grep $process | grep -v grep | awk \'{print \$2}\'"
- send "\r"
- expect -re "\n(\[0-9]*)\n" {
- set pid $expect_out(1,string)
- foreach element $pid {
- puts "-------------------------"
- puts $element
- puts "-------------------------"
- }
- }
- send "exit\r"
- expect eof
复制代码 为什么我这样写,就是打印不出来呢? |
|