Recently in the Zabbix, the company has six new servers. When the Zabbix client is deployed, the baby is really angry. Grandpa's always so repetitive work is also not AH. But as a war five slag, what else can be mixed with rice? Think of last year wrote a expect blog, so came the inspiration. God, please don't squirt me. So I decided to play a bit of technical little difficulty, remote automatic synchronization. Client software. So I revisit the expect. Just beginning to feel very rare, after writing a few scripts. It feels the same, no technical difficulty. Just write the first script success when the excitement of not to. The face has not seen the appearance of the state, haha! A good memory is better than writing a blog, so I wrote this blog, this. Serve the dishes below.
#!/bin/bash
p= "Maomaochong"
For i in ' Echo ' # because I am testing on my own computer so write, more than one can be written ' SEQ 100 114 ' indicates a range
Do
/usr/bin/expect <<-eof
Spawn scp-r/usr/local/zabbix-agent.tar.gz [email protected]${i}:/home/zgabe/
Expect {
"Yes/no" {send "yes\r"} #\r: Indicates OK
}
Expect {
"Password:" {send "$P \ r"}
}
Expect "*$" #普通用户是 $,root user is #
Send "exit\r"
Expect EOF
EOF #expect语句结束
Done #shell的for循环结束.
You can test the script syntax for errors with the Shell-n script file name in the process again
shell-x The script name to view the execution process if the script has an error . will show up directly. Every step is very detailed. Easy to troubleshoot errors
This article is from "Desert Camel" blog, please make sure to keep this source http://maomaochong.blog.51cto.com/9260445/1812455
Shell nested expect for loop nesting expect implementing file remote replication