One of the problems I have encountered in recent weeks is to work in a systematic way the mime command running on multiple servers (just under 200 servers).
Because this is more than annoying (especially the routine), then remembering the old command expect "I started looking for a script to automate some of this type of task.
This is how I met with the script repository of nixCraft, where rescue a nice script to enter an ssh server from the key parameter, the server and the command to execute.
After some modifications to the script remained the same thing more or less:
With this script you can eg know how long it takes on one of our servers:
With this, we have only solved half the problem, which is to run the command without having to wait until we ask the key. But the second part is the easiest.
We
generating a file from the servers and their keys, something like:
And with a simple script like this, we traverse the list server and run the command key and all of them:
Because this is more than annoying (especially the routine), then remembering the old command expect "I started looking for a script to automate some of this type of task.
This is how I met with the script repository of nixCraft, where rescue a nice script to enter an ssh server from the key parameter, the server and the command to execute.
After some modifications to the script remained the same thing more or less:
# / usr / bin / expect-f
# # This program is free software; You Can redistribute it and / or modify
# it under the Terms of the GNU General Public License as published by
# the Free Software Foundation; Either version 2, or (at your option) # Any Later
version.
# # For use:
#. / Server command arg1 sshlogin.exp password
# # ---------------------------- ------------------------------------------
# Basado en http://bash.cyberciti.biz/security/expect-ssh-login-script/
# ----------------------------------------------------------------------
# set Variables
set password [lrange $argv 0 0]
set ipaddr [lrange $argv 1 1]
set scriptname [lrange $argv 2 2]
set arg1 [lrange $argv 3 3]
set timeout -1
# now connect to remote UNIX box (ipaddr) with given script to execute
spawn -noecho ssh -o "ConnectTimeout 10" root@$ipaddr $scriptname $arg1
match_max 100000
expect {
# first time
"*continue connecting*" { send -- "yes\r"; exp_continue }
# for
key passphase "* passphrase *" {send - "$ password \\ r";}
exp_continue
# for password
"* assword *" {send - "$ password \\ r";}
exp_continue
# for timeout
timeout {exit}}
With this script you can eg know how long it takes on one of our servers:
uptime. / sshlogin.exp la_clave el_server
With this, we have only solved half the problem, which is to run the command without having to wait until we ask the key. But the second part is the easiest.
We
generating a file from the servers and their keys, something like:
servidor_1: clave_1
Server_2: clave_2
servidor_3: clave_3
And with a simple script like this, we traverse the list server and run the command key and all of them:
# / bin / bash mkdir-p log
for line in `cat` server.lst
do server = `echo $ line > Log / $ server done
With this you can download a script from a server and run on the remote server and save the result on the local machine.
0 comments:
Post a Comment