Shell enables interactive login to one and simultaneous management of multiple machines

Source: Internet
Author: User

Shell enables interactive login to one and simultaneous management of multiple machines

Recently, in order to check the hard drive of the company's servers, we need to open more than 10 servers to check the servers. However, these 10 servers use the same command, which is too troublesome to perform one operation.

Then I thought that I needed to create an Ip folder for interactive login and put all your Ip account and password in it. Then, when performing the round CT operation, it will not end until the loop ends, is it fun.
Except CT interactive installation is required. You can directly install yum install unzip CT-y. Of course, you can also compile and install it. I like yum for convenience. I will not talk about it here. paste the code.

The Code is as follows:

#! /Usr/bin/CT-f
Set f [open./ip r]
While {[gets $ f line]> = 0 }{
Set ip [lindex $ line 0]
Set pwd [lindex $ line 2]
Spawn ssh-o StrictHostKeyChecking = no $ ip
Reset CT "* password:" {send "$ pwd \ r "}
CT "#"
Send "ifconfig \ r"
Send "iptables-I INPUT-m state -- state NEW-m tcp-p tcp -- dport 123-j ACCEPT \ r"
Send "service iptables save \ r"
Send "yum install ntpdate-y \ r"
Send "/usr/sbin/ntpdate 0.cn.pool.ntp.org \ r"
Send "echo '*/10 ***** sh/root/testdisk. Sh'>/var/spool/cron/root \ r"
Send "echo '10 5 ***/usr/sbin/ntpdate 0.cn.pool.ntp.org '>/var/spool/cron/root \ r"
Send "exit \ r"
Interact
}

The disk detection script is as follows:

#! /Bin/bash
PATH =/bin:/etc:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin :~ /Bin
Export PATH
Dd if =/dev/zero of =/test. dbf bs = 1024 k count = 1000 2> writedisk.txt
If [$? -Eq 0]
Then
W = 'Tail-n 1 writedisk.txt | cut-d,-f3 | sed's // g''
Dd if =/test. dbf of =/dev/null bs = 1024 k 2> readdisk.txt
If [$? -Eq 0]
Then
R = 'Tail-n 1 readdisk.txt | cut-d,-f3 | sed's // g''
S = 'date-d today + "% Y-% m-% d, % T "'
Echo $ s -- $ r, $ w> upload txt
Else
Echo "fail"
Fi
Else
Echo "fail"
Fi

This article permanently updates the link address:

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.