Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5687574
  • 博文数量: 675
  • 博客积分: 20301
  • 博客等级: 上将
  • 技术积分: 7671
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-31 16:15
文章分类

全部博文(675)

文章存档

2012年(1)

2011年(20)

2010年(14)

2009年(63)

2008年(118)

2007年(141)

2006年(318)

分类: LINUX

2009-07-02 16:30:32

最近一直在忙项目验收,没有写多少blog,现在补上。

现在项目中需要大量的机器一起跑实验,以前师兄是写了一个expect脚本来串行的登录到各个机器,然后执行相应的命令,但是这么下来,下发实验开始的命令就要10几分钟。实在,忍不了,便开始寻找一些分布式机器管理软件。

软件一:omnitty

缺点:
1. 所有的操作都是手动完成,不能自动完成
2. 不能指定登录用户名,但是可以在host指定上使用一些技巧,例如 root@192.168.1.2
3. 不能指定端口

注意:实际上是omnitty在读取文件有问题,可以使用下面的patch解决问题,patch针对omnitty-0.3.0:
diff -uNr omnitty-0.3.0/main.c omnitty-0.3.0-patched/main.c
--- omnitty-0.3.0/main.c    2005-10-26 06:08:25.000000000 +0800
+++ omnitty-0.3.0-patched/main.c    2009-07-03 16:44:03.000000000 +0800
@@ -20,6 +20,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  * Copyright (c) 2002 Bruno T. C. de Oliveira
  */
+#define _GNU_SOURCE
+#include
 
 #include
 #include
@@ -243,10 +245,19 @@
 }
 
 static void add_machines_from_file(const char *file) {
-   static char buf[128];
+   //Fixed by WangYao 09-07-03
+   //static char buf[128];
+   char *buf = NULL;
    bool pipe = false;
    FILE *f;
 
+   buf = (char *)malloc(128);
+   if(buf == NULL)
+   {
+       perror("malloc");
+       exit(-1);
+   }
+
    if (getenv("OMNITTY_AT_COMMAND")) {
       /* popen() a command */
       pipe = true;
@@ -268,7 +279,19 @@
    minibuf_put(minibuf, pipe ? "Adding machines supplied by command..." :
                                "Adding machines from file...", 0x70);
 
-   while (1 == fscanf(f, "%s", buf)) machmgr_add(buf);
+   //Fixed by WangYao 09-07-03
+   //-p 10000 root@192.168.1.1
+   //while (1 == fscanf(f, "%s", buf)) machmgr_add(buf);
+   ssize_t nread=0;
+   size_t len=127;
+   while ((nread = getline(&buf, &len, f)) != -1)
+   {
+       machmgr_add(buf);
+       memset(buf, 0, sizeof(buf));
+   }
+
+   if(buf)
+       free(buf);
 
    if (pipe) {
       if (0 != pclose(f))
可以直接下载打过patch的源码包:
文件:omnitty-0.3.0-patched.tar.gz
大小:49KB
下载:下载


优点:
1. 广播模式非常方便
2. 支持密码登录,在广播模式下,所有机器密码一样的情况下,登录非常方便;如果密码不一样,只能挨个敲密码了;-(

软件二:dsh

缺点:
1.不能指定登录用户名,但是可以在host指定上使用一些技巧,例如 root@192.168.1.2
2.必须使用密钥登录
3.只有ssh的功能,没有scp的功能

注意:dsh指定端口的方法
$ dsh -M -c -f host -o -p10000 uname


优点:
1. 输出到标准输出上,看起来比较方便

一个在分布式机器上运行一条命令的shell脚本RunCmd.sh:
#!/bin/sh

DSH=/usr/bin/dsh
#$DSH -M -c -f hosts/root@host "$@"
$DSH -M -c -f hosts/root@host $*


软件三: pssh

缺点:
1. 在执行命令的时候,所有的输出只能够存放到一个文件中,有些不方便
2. 必须使用密钥登录

优点:
1. 可以指定不同的登录用户
2. 支持scp功能,包括从本地拷贝文件到远端,从远端拷贝文件到本地

脚本scpl2r.sh,将文件从本地拷贝道远端
#!/bin/sh

if [ $# -ne 2 ];then
    echo "Usage: scpl2r.sh localfile remotefile"
    exit
fi

srcfile=$1
dstfile=$2

PSCP=/usr/bin/parallel-scp
$PSCP -h hosts/host -l root $srcfile $dstfile


脚本scpr2l.sh,将文件从远端拷贝到本地
#!/bin/sh

if [ $# -ne 2 ];then
    echo "Usage: scpl2r.sh localfile remotefile"
    exit
fi

srcfile=$1
dstfile=$2

PSLURP=/usr/bin/parallel-slurp
$PSLURP -h hosts/host -l root -L log/ $srcfile $dstfile



参考:

~dancer/software/dsh.html.en

阅读(2824) | 评论(0) | 转发(0) |
0

上一篇:shell的IFS

下一篇:shell脚本中的参数

给主人留下些什么吧!~~