• rex run 传参


    怎么给任务传递参数?
    
    task 'mytask', group => "myservers", sub {
      my $parameters = shift;
      my $parameter1_value = $parameters->{parameter1};
      my $parameter2_value = $parameters->{parameter2};
       print "$parameter1_value=$parameter1_value
    ";
       print "$parameter2_value=$parameter2_value
    ";
    };
    
    task 'mytask', group => "myservers", sub {
      my $parameters = shift;
      my $parameter1_value = $parameters->{parameter1};
      my $parameter2_value = $parameters->{parameter2};
       print "$parameter1_value=$parameter1_value
    ";
       print "$parameter2_value=$parameter2_value
    ";
    };
    
    [root@node01 my-first-rex-project]# rex mytask --parameter1=aaaaa --parameter2=bbbb
    [2017-04-29 10:41:54] INFO - Running task mytask on 192.168.137.3
    $parameter1_value=aaaaa
    $parameter2_value=bbbb
    [2017-04-29 10:42:05] INFO - All tasks successful on all hosts
    
    
    desc "Start Mysql Service";
    task "start_mysql", group => "myservers", sub {
        service "mysql" => "start";
    };
    
    task 'mytask', group => "myservers", sub {
      my $parameters = shift;
      my $parameter1_value = $parameters->{parameter1};
      my $parameter2_value = $parameters->{parameter2};
       print "$parameter1_value=$parameter1_value
    ";
       print "$parameter2_value=$parameter2_value
    ";
       my $output = run "ps -ef | grep $parameter1_value | grep $parameter2_value";
       say $output;
    };
    [root@node01 my-first-rex-project]# rex mytask --parameter1=a1.sh --parameter2=mqm
    [2017-04-29 10:44:34] INFO - Running task mytask on 192.168.137.3
    $parameter1_value=a1.sh
    $parameter2_value=mqm
    mqm      24297 24272  0 01:46 pts/0    00:00:00 vim a1.sh
    root     24380 24298  0 01:46 ?        00:00:00 bash -c LC_ALL=C ; export LC_ALL; PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/pkg/bin:/usr/pkg/sbin; export PATH; ps -ef | grep a1.sh | grep mqm  
    [2017-04-29 10:44:45] INFO - All tasks successful on all hosts
    [root@node01 my-first-rex-project]# 
    

  • 相关阅读:
    24-移动端app数据爬取
    24-移动端app数据爬取
    18闭包
    mysql日期 获取本月第一天 获取下个月的第一天
    介绍shell的来龙去脉给你看
    RHEL 和centos 的区别
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/fs/FSDataInputStream
    CDH管理界面查看各框架的版本(hive为例)
    Cloudera hadoop配置文件地址和修改配置属性方法
    idea快速创建级联目录
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349746.html
Copyright © 2020-2023  润新知