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

  • 相关阅读:
    SharePoint 2010“.NET研究” BI:Chart WebPart 狼人:
    .NET分布“.NET研究”式架构开发实战之一 故事起源 狼人:
    C#中的loc“.NET研究”k关键字 狼人:
    .NET 分布式架构开发“.NET研究”实战之三 数据访问深入一点的思考 狼人:
    舍WebServic“.NET研究”e 用.NET4中jQuery调用WCF 狼人:
    Visual Studio 2010构建Web浏“.NET研究”览器应用程序 狼人:
    强类型ASP.NET数据绑定改进“.NET研究”版 狼人:
    Visual Studio 2008单元测试_数据“.NET研究”库测试 狼人:
    主题执行过程改进建设中的常见奖励措施
    分类栏目Thinkphp实现无限极分类
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349729.html
Copyright © 2011-2022 走看看