Shell nested expect for loop nesting expect implementing file remote replication

Source: Internet
Author: User

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/1812457

Shell nested expect for loop nesting expect implementing file remote replication

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.