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

  • 相关阅读:
    android.database.sqlite.SQLiteException: no such column: aaa (code 1): , while compiling: DELETE FROM users WHERE user_name=aaa解决办法
    安卓开发经常闪退的原因及解决方法
    pycharm破解
    解决命名空间“System.Web.Mvc”中不存在类型或命名空间名称“Ajax”(是否缺少程序集引用?)
    Request.Params
    MVC查找排序分页学习
    js jq输入框中按回车触发提交事件,用户在页面输入后按回车(Enter键)进行
    前端入门1-基础概念
    系统应用集成过程中的一些坑
    继续封装个 Volley 组件
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349729.html
Copyright © 2011-2022 走看看