• Rex


    Rex - 远程执行:
    
    [root@node01 my-first-rex-project]# cat Rexfile
    use Rex -feature => ['1.0'];
    no strict;
    use Rex::Misc::ShellBlock;
    use Rex::Misc::ScanBlock;
     user "root";
     password "1234567";
     
     desc "Show Unix version";
     task "uname", sub {
        say run "ifconfig -a | grep inet";
     };
    
     
    [root@node01 my-first-rex-project]# rex uname
    [2017-05-03 20:51:29] INFO - Running task uname on <local>
              inet addr:192.168.137.2  Bcast:192.168.137.255  Mask:255.255.255.0          inet6 addr: fe80::20c:29ff:fe29:8eac/64 Scope:Link          inet addr:127.0.0.1  Mask:255.0.0.0          inet6 addr: ::1/128 Scope:Host
    [2017-05-03 20:51:30] INFO - All tasks successful on all hosts
    [root@node01 my-first-rex-project]# 
    
    不 task "uname", sub { 
    
    不指定group 统计的是本机:
    
    
    
    统计远程机器:
    
    [root@node01 my-first-rex-project]# cat Rexfile
    use Rex -feature => ['1.0'];
    no strict;
    use Rex::Misc::ShellBlock;
    use Rex::Misc::ScanBlock;
     user "root";
     password "1234567";
     group myservers => "192.168.137.3"; 
     desc "Show Unix version";
     task "uname", group => "myservers", sub {
        say run "ifconfig -a | grep inet";
     };
     
    [root@node01 my-first-rex-project]# rex uname
    [2017-05-03 20:54:47] INFO - Running task uname on 192.168.137.3
              inet addr:192.168.137.3  Bcast:192.168.137.255  Mask:255.255.255.0          inet6 addr: fe80::20c:29ff:fe14:8fc1/64 Scope:Link          inet addr:127.0.0.1  Mask:255.0.0.0          inet6 addr: ::1/128 Scope:Host
    [2017-05-03 20:54:58] INFO - All tasks successful on all hosts
    [root@node01 my-first-rex-project]# 
    
    
    类方法
    
    get_current_connection
    
    [root@node01 my-first-rex-project]# cat Rexfile
    use Rex -feature => ['1.0'];
    no strict;
    use Rex::Misc::ShellBlock;
    use Rex::Misc::ScanBlock;
     user "root";
     password "1234567";
     group myservers => "192.168.137.3"; 
     desc "Show Unix version";
     task "uname", group => "myservers", sub {
        say run "ifconfig -a | grep inet";
    my $rhash=Rex::get_current_connection();
    print %{$rhash};
    print "
    ";
     };
     
    [root@node01 my-first-rex-project]# rex uname
    [2017-05-03 21:02:48] INFO - Running task uname on 192.168.137.3
              inet addr:192.168.137.3  Bcast:192.168.137.255  Mask:255.255.255.0          inet6 addr: fe80::20c:29ff:fe14:8fc1/64 Scope:Link          inet addr:127.0.0.1  Mask:255.0.0.0          inet6 addr: ::1/128 Scope:Host
    notifyRex::Notify=HASH(0x254fdd0)cacheRex::Interface::Cache::Base=HASH(0x254fe30)server192.168.137.3taskARRAY(0x254fe90)sshprofilerRex::Profiler=HASH(0x254fc38)connRex::Interface::Connection::OpenSSH=HASH(0x254ff38)reporterRex::Report::Base=HASH(0x254fea8)
    [2017-05-03 21:03:00] INFO - All tasks successful on all hosts
    
    
    [root@node01 my-first-rex-project]# rex uname | grep '192.168.137.3'
    [2017-05-03 21:05:25] INFO - Running task uname on 192.168.137.3
              inet addr:192.168.137.3  Bcast:192.168.137.255  Mask:255.255.255.0          inet6 addr: fe80::20c:29ff:fe14:8fc1/64 Scope:Link          inet addr:127.0.0.1  Mask:255.0.0.0          inet6 addr: ::1/128 Scope:Host
                                   'name' => '192.168.137.3',
                                                                              '_host' => '192.168.137.3',
                                                                              '_host_squared' => '192.168.137.3',
                                                                              '_ctl_path' => '/root/.libnet-openssh-perl/root-192.168.137.3-2-8089-364094',
                                                          'name' => '192.168.137.3',
    [2017-05-03 21:05:37] INFO - All tasks successful on all hosts

  • 相关阅读:
    MyEclipse 中无法直接使用BaseEncoder问题
    一个随机数发生器 用于在服务器和客户机直接进行安全性验证的类
    JS中如何防止表单重复提交问题
    Centos 7 配置tomcat服务器
    tomcat 报错出现 jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
    Tomcat 报错 The APR based Apache Tomcat Native library which allows optimal performance in production environmen
    阿里云服务器Centos 7安装PHP
    网站开发过程中的URL写法
    Servlet防止盗链
    2018年蓝桥杯java b组第八题
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349729.html
Copyright © 2020-2023  润新知