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: