A script to modify the requirements of 10 machine host files

Source: Internet
Author: User

Tag:ar   os   sp   for   on    file    bs   ad   as   

#!/bin/bashecho  "Enter heno ' S password" read henopasswordecho  "Enter root" s  Password "read rootpasswordfor i in 11 12 13 14 15 16 17  18 19 20 21;        do                 ip= "192.168.10." $i                 comand= "ssh  -o stricthostkeychecking=no [email protected] $ip "                 expect -c  "                          set timeout 60;                         spawn  $comand;                         expect {                                  \ "[email protected] $ip ' s password:\ '  {send \ "$henoPassword \r\"; exp_continue}                                  \ "Terry\"  {send \ "Su -\r\"; exp_continue}                                  \ "Password:\"  {send \ "$ Rootpassword\r\ ";  exp_continue}                                 \ "[email  Protected]\ " {send \" sed -i  ' s/192.168.*     analysis.xxxx.com/ 192.168.10.221     analysis.xxxx.com/g '  /etc/hosts\rexit\rexit\r\ ';  exp_ continue}                         }                          "         done


Script logic:

1. Read the user name password from the command line

Log on to server, cut to root--"modify file--Exit root--exit the server---loop

Attention:

If the machine does not have except installed, you need to install expect

CentOS can be installed simply by installing Yum install expect*



A script to modify the requirements of 10 machine host files

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.