Mussh(MUltihost SSH Wrapper)是一个SHELL脚本,用来同时在多台主机上执行SSH命令或脚本,使用ssh-agent和RSA/DSA来减少密码的输入次数。

[root@monitor ~]# cat /etc/redhat-release
CentOS release 5.4 (Final)
[root@monitor ~]# rpm -qa |grep epel
epel-release-5-4
[root@monitor ~]# yum install mussh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirror.bjtu.edu.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mussh.noarch 0:1.0-0.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================
 Package                                Arch                                    Version                                    Repository                             Size
=======================================================================================================================================================================
Updating:
 mussh                                  noarch                                  1.0-0.el5                                  epel                                   16 k

Transaction Summary
=======================================================================================================================================================================
Install      0 Package(s)         
Update       1 Package(s)         
Remove       0 Package(s)         

Total download size: 16 k
Is this ok [y/N]: y
Downloading Packages:
mussh-1.0-0.el5.noarch.rpm                                                                                                                      |  16 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating       : mussh                                                                                                                                           1/2 
  Cleanup        : mussh                                                                                                                                           2/2 

Updated:
  mussh.noarch 0:1.0-0.el5                                                                                                                                             

Complete!
因为我的系统原来装有mussh,所以显示的升级到1.0版本了。
[root@monitor ~]#mussh --help
Usage: mussh [OPTIONS] <-h host.. | -H hostfile> [-c cmd] [-C scriptfile]
mussh --help        for full help text

Send a command or list of commands to multiple hosts.

OPTIONS:
        --help          This text.
        -d [n]          Verbose debug.  Prints each action, all hosts
                        and commands to be executed to STDERR.  'n' can
                        be from 0 to 2.
        -v [n]          Ssh debug levels.  Can be from 0 to 3.
        -m [n]          Run concurrently on 'n' hosts at a time (asynchronous).
                        Use '0' (zero) for infinite. (default if -m)
        -q              No output unless necessary. 
        -i <identity> [identity ..]
                        Load an identity file.  May be used
                        more than once.
        -o <ssh-args>   Args to pass to ssh with -o option.
        -a              Force loading ssh-agent.
        -A              Do NOT load ssh-agent.
        -b              Print each hosts' output in a block without mingling
                        with other hosts' output.
        -B              Allow hosts' output to mingle. (default)
        -u              Unique.  Eliminate duplicate hosts. (default)
        -U              Do NOT make host list unique.
        -P              Do NOT fall back to passwords on any host.  This will
                        skip hosts where keys fail.
        -l <login>      Use 'login' when no other is specified with hostname.
        -L <login>      Force use of 'login' name on all hosts.
        -s <shell>      Path to shell on remote host. (Default: bash)
        -t <secs>       Timeout setting for each session.
                        (requires openssh 3.8 or newer)
        -V              Print version info and exit.
PROXY ARGS:
        -p [user@]<host>
                        Host to use as proxy.  (Must have mussh installed)
        -po <ssh-args>        Args to pass to ssh on proxy with -o option.
HOST ARGS:
        -h [user@]<host> [[user@]<host> ..]
                        Add a host to list of hosts.  May be
                        used more than once.
        -H <file> [file ..]
                        Add contents of file(s) to list of hosts.
                        Files should have one host per line.  Use
                        "#" for comments.
COMMAND ARGS:
If neither is specified, commands will be read from standard input.
        -c <command>    Add a command or quoted list of commands and
                        args to list of commands to be executed on
                        each host.  May be used more than once.
        -C <file> [file ..]
                        Add file contents to list of commands to be
                        executed on each host.  May be used more
                        than once.

At least one host is required.  Arguments are in no particular order.

EXAMPLES:
mussh -H ./linuxhosts -C spfiles/testscript.sh
mussh -c "cat /etc/hosts" -h myhost.mydomain.com

Comments and Bug Reports: doughnut@doughnut.net
此处略去ssh密钥验证过程
[root@monitor tool]# cat 3.txt 
10.0.3.2
10.0.3.3
10.0.3.4
10.0.3.5
10.0.3.6
10.0.3.7
10.0.3.8
10.0.3.9
执行命令如下
[root@monitor tool]# mussh -H ./3.txt -c "w"
Identity added: /root/.ssh/id_dsa (/root/.ssh/id_dsa)
10.0.3.2: 10:15:25 up 20 days, 43 min,  0 users,  load average: 0.22, 0.26, 0.30
10.0.3.2: USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
10.0.3.3: 10:15:25 up 64 days, 59 min,  0 users,  load average: 0.31, 0.29, 0.32
10.0.3.3: USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
10.0.3.4: 10:15:25 up 273 days, 23:53,  0 users,  load average: 0.36, 0.35, 0.38
10.0.3.4: USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
10.0.3.5: 10:15:25 up 27 days,  1:57,  0 users,  load average: 0.32, 0.32, 0.33
10.0.3.5: USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
10.0.3.6: 10:15:25 up 273 days, 23:53,  0 users,  load average: 0.24, 0.31, 0.33
10.0.3.6: USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
10.0.3.7: 10:15:25 up 52 days, 58 min,  0 users,  load average: 0.57, 0.43, 0.37
10.0.3.7: USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
10.0.3.8: 10:15:25 up 41 days,  1:12,  0 users,  load average: 0.30, 0.33, 0.37
10.0.3.8: USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
10.0.3.9: 10:15:25 up 23 days, 40 min,  0 users,  load average: 0.33, 0.34, 0.34
10.0.3.9: USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
执行脚本如下
[root@monitor tool]# mussh -H ./3.txt -C ./sh/ip.sh 
Identity added: /root/.ssh/id_dsa (/root/.ssh/id_dsa)
10.0.3.2: addr:10.0.3.2
10.0.3.3: addr:10.0.3.3
10.0.3.4: addr:10.0.3.4
10.0.3.5: addr:10.0.3.5
10.0.3.6: addr:10.0.3.6
10.0.3.7: addr:10.0.3.7
10.0.3.8: addr:10.0.3.8
10.0.3.9: addr:10.0.3.9
并发执行如下
[root@monitor tool]# mussh -m 9 -H ./3.txt -C ./sh/ip.sh 
Identity added: /root/.ssh/id_dsa (/root/.ssh/id_dsa)
10.0.3.2: addr:10.0.3.2
10.0.3.3: addr:10.0.3.3
10.0.3.4: addr:10.0.3.4
10.0.3.5: addr:10.0.3.5
10.0.3.6: addr:10.0.3.6
10.0.3.7: addr:10.0.3.7
10.0.3.8: addr:10.0.3.8
10.0.3.9: addr:10.0.3.9
[root@monitor tool]# 

One thought on “Mussh”

发表评论

电子邮件地址不会被公开。 必填项已用*标注