expect在执行命令返回结果中,有时候只返回一些结果,并卡住
在bash中调用expect登录远程主机执行命令。发现expect在执行命令find时,有时候返回正常结果,有时候只返回一些结果,并卡住,然后就不退出。
登录的是同一个远程主机。同一时间执行脚本10次,基本上有5次是卡住的。
将|xargs -I {} last -f {} 改为 -exec last -f \;也是一样的情况。请指教下原因。谢谢。
expect <<EOF
set timeout -1
log_file ${tmpdir}/${atype}_tmp.txt
spawn ssh ${user}@${ip}
expect {
"yes/no" { send "yes\r";exp_continue}
"assword" { send "${pw}\r"}
}
expect "#"
send "touch -t ${last_time}last_time.txt \r"
expect "#"
send "find /var/log -type f -name \"wtmp*\" -newer \"last_time.txt\" |xargs -I {} last -f {} \r"
expect "#"
send " rm-f last_time.txt \r"
expect "#"
send"exit\r"
expect eof
EOF
expect次数太多了,为什么不把脚本放到远程主机呢?
用spawn ssh 执行远程主机shell脚本,
这样只需expect一次就行了。
expect {
"yes/no" {
send "yes\n"
expect "password:"
send "$passwd\n"
}
"password:" {send "$passwd\n"}
}
另外 linux下 回车换行 是 \n. set timeout -1
回复 2# salmon5
因为涉及的主机较多,不方便都上传到远程主机上操作,只适宜发送指令到远程主机。另外,r和n 回车换行测试还是不行。
试试使用SaltStack吧 interpreter 或者 exp_internal1看下。
expect-re
interpreter 或者 exp_internal1看下。
expect-re
页:
[1]