Implement Parallel CT scripts for managing multiple servers at the same time

Source: Internet
Author: User

Recently, I learned the expect scripting language through mongoingshortct books. This scripting language is an extension of the tcl language and is used to solve the problem that some tools cannot automatically interact with each other. For example, when logging on to ssh, you cannot specify a password in the command. The following is a simple example of using reverse CT to manage multiple servers:

1234567891011121314151617181920212223242526272829303132 #! /Usr/bin/login CT # purpose: auto run command on multiple servers # how to: mms <user> <cmd> # write by zhumaohai. # blog: http://www.centoscn.com/if?#argc <2} {puts "usage: mms <user> <cmd> "exit1} # set serverssetSERVERS {" 192.168.0.100 "" 192.168.0.101 "" 192.168.0.102 "} # set passwordsetPASSWORDS (user1)" passwd1 "setPASSWORDS (user2) "passwd2" # get virablessetUSER [lindex $ argv 0] setCMD [lrange $ argv 1 end] setpasswd $ PASSWORDS ($ USER) foreach x $ SERVERS {evalspawnssh-l $ USER $ x $ CMDexpect {"password" {send "$ passwdr"} "yes/no" {send "yesr"; exp_continue ;}} CT eof}

1. Here we define the three servers 192.168.0.100 192.168.0.101 192.168.0.102, the user user1 password is passwd1, and the user user2 password is passwd2. If the script file name is ms, the usage is:
./Ms user commands
Such as./MS user1 date
2. When using the script, make sure that the kernel CT command is installed on the system. centos is installed using yum install kernel CT and ubuntu is installed using apt-get install kernel CT.

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.