• Rex.pm


    Rex - Remote Execution
    
    描述:
    
    Rex 是一个命令行工具执行命令在远程servers,
    
    定义tasks在perl和执行它们在远程服务器
    
     task "task1", sub {
    
        say template("ntpd.conf");
    
     };
    
    
    task "task2", group=>"myservers", sub {
      my $output = run "ld";
      say '----------------------';
      say $?;
      say '----------------------';
      say $output;
    };
    [root@node01 Rex]# rex task2
    [2017-05-01 07:04:50] INFO - Running task task2 on 192.168.137.3
    ----------------------
    1
    ----------------------
    
    [2017-05-01 07:05:01] INFO - All tasks successful on all hosts
    [root@node01 Rex]# rex task1
    [2017-05-01 07:05:14] INFO - Running task task1 on <local>
    aaaaaaaa
    bbbbbbbb
    cccccccc
    111111111
    22222222
    33333333
    
    
    Rex 可以用于:
    
    1.利用web 应用到服务器顺序的或者并发的
    
    2.自动执行任务
    
    3.提供 servers使用Rex的内置工具
    
    简介:
    
    [root@node01 Rex]# cat Rexfile
    use Rex -feature => ['1.0'];
    no strict;
    
    user "root";
    private_key "/root/.ssh/id_rsa";  ##私钥
    public_key "/root/.ssh/id_rsa.pub"; ##公钥
    key_auth;
    group myservers => "192.168.137.3";
         use Rex -feature => [qw/1.3/];
       
       
        desc "Show Unix version";
        task "uname", group=>"myservers", sub {
           say run "uname -a";
        };
     
    [root@node01 Rex]# rex uname
    [2017-05-01 07:39:25] INFO - Running task uname on 192.168.137.3
    Linux node2 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
    [2017-05-01 07:39:36] INFO - All tasks successful on all hosts
    
    类方法:
    
    [root@node01 Rex]# cat Rexfile
    use Rex -feature => ['1.0'];
    no strict;
    use Data::Dumper;
    
    user "root";
    private_key "/root/.ssh/id_rsa";  ##私钥
    public_key "/root/.ssh/id_rsa.pub"; ##公钥
    key_auth;
    group myservers => "192.168.137.3";
         use Rex -feature => [qw/1.3/];
       
       
        desc "Show Unix version";
        task "uname", group=>"myservers", sub {
           say run "uname -a";
           #print Dumper( Rex::get_current_connection());
           print "
    ";
           print Rex::get_current_connection()->{server};
           
        };
     
    [root@node01 Rex]# rex uname
    [2017-05-01 07:48:12] INFO - Running task uname on 192.168.137.3
    Linux node2 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
    
    192.168.137.3[2017-05-01 07:48:23] INFO - All tasks successful on all hosts
    

  • 相关阅读:
    JavaScript随机数
    javascript函数
    hdu 4122(RMQ)2011福州现场赛B题
    hdu 4119 (模拟+字符串)成都现场赛I题
    hdu 4118(树形dp) 成都现场赛H题
    hdu 4115(2-SAT) 2011 成都现场赛E题
    Codeforces Round #237 (Div. 2) 解题报告
    Codeforces Round #234 (Div. 2) 解题报告
    uva 1411(二分图最大权匹配)
    uva 11383(二分图最大权匹配)
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349737.html
Copyright © 2020-2023  润新知