我有以下代码段,我将连接到远程服务器并将dhcp config和dhcpd服务状态捕获到文件中。
#!/bin/bash
RET=$(expect -c "
puts \"invoke SSH \"
spawn ssh root@10.255.99.10
expect {
\"(yes/no)\" {send -- \"yes\n\"}
\"assword:\" {send -- \"yt_xk39b\n\"}
\"> \" {send -- \"\n\"}
}
expect {
\"assword:\" {send -- \"yt_xk39b\n\"}
\"> \" {send -- \"\n\"}
}
expect {
\"> \" {send -- \"cat /etc/dhcp/dhcpd.conf > /tmp/dhcp.txt\n\"}
}
expect {
\"> \" {send -- \"date\n\"}
}
expect {
\"> \" {send -- \"service dhcpd status >> /tmp/dhcp.txt\n\"}
}
expect {
\"> \" {puts \"finish.\"}
}
")
以下是在调试模式下执行脚本
root@ac3tiams> sh -x /tmp/dummy_expect.sh
++ expect -c '
puts "invoke SSH "
spawn ssh root@10.255.99.10
expect {
"(yes/no)" {send -- "yes\n"}
"assword:" {send -- "yt_xk39b\n"}
"> " {send -- "\n"}
}
expect {
"assword:" {send -- "yt_xk39b\n"}
"> " {send -- "\n"}
}
expect {
"> " {send -- "cat /etc/dhcp/dhcpd.conf > /tmp/dhcp.txt\n"}
}
expect {
"> " {send -- "date\n"}
}
expect {
"> " {send -- "service dhcpd status >> /tmp/dhcp.txt\n"}
}
expect {
"> " {puts "finish."}
}
'
+ RET='invoke SSH
spawn ssh root@10.255.99.10
|-----------------------------------------------------------------|
| This system is for the use of authorized users only. |
| Individuals using this computer system without authority, or in |
| excess of their authority, are subject to having all of their |
| activities on this system monitored and recorded by system |
| personnel. |
| Anyone using this system expressly consents to such monitoring |
| and is advised that if such monitoring reveals possible |
| evidence of criminal activity, system personnel may provide the |
| evidence of such monitoring to law enforcement officials. |
|-----------------------------------------------------------------|
Last login: Fri Feb 5 12:08:38 2010 from 10.255.99.10
root@ac3tiams>
root@ac3tiams>
root@ac3tiams> cat /etc/dhcp/dhcpd.conf > /tmp/dhcp.txt
date
root@ac3tiams> date
service dhcpd status >> /tmp/dhcp.txt
finish.'
root@ac3tiams>
这里我能够捕获dhcp conf,但无法捕获文件的dhcp服务状态。你能帮帮我吗?