zoukankan      html  css  js  c++  java
  • 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
    

  • 相关阅读:
    人工智能深度学习入门练习之(6)求和方法2
    人工智能深度学习入门练习之(5)求和
    人工智能深度学习入门练习之(4)矩阵实现
    人工智能深度学习入门练习之(3)求导
    阿里巴巴Java开发手册(格式规约篇)——查自己的漏-补自己的缺
    阿里巴巴Java开发手册(命名规范/常量定义篇)——查自己的漏-补自己的缺
    自学git
    IE浏览器兼容性问题输出
    项目经验输出
    Ping任务管理模块-JavaWeb
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349737.html
Copyright © 2011-2022 走看看