zoukankan      html  css  js  c++  java
  • rex 上传文件并远程执行

    Rex::Commands::File - Transparent File Manipulation:
    
    
    名称
    
    Rex::Commands::File - Transparent File Manipulation
    
    
    task "read-passwd2", "192.168.137.3", sub {
       say cat "/etc/passwd";
     };
    
    [root@node01 Rex]# rex "read-passwd2" | grep tlcb
    [2017-09-12 02:16:08] WARN - Please use only the following characters for task names:
    [2017-09-12 02:16:08] WARN -   A-Z, a-z, 0-9 and _
    [2017-09-12 02:16:08] WARN - Also the task should start with A-Z or a-z
    [2017-09-12 02:16:08] WARN - You can disable this warning by setting feature flag: disable_taskname_warning
    [2017-09-12 02:16:08] INFO - Running task read-passwd2 on 192.168.137.3
    tlcb:x:504:504::/home/tlcb:/bin/bash
    [2017-09-12 02:16:09] INFO - All tasks successful on all hosts
    [root@node01 Rex]# 
    
    file($file_name, %options)
    
    这个函数是Install file命令的缩写,请使用这个函数来上传文件:
    
    task "prepare01", "192.168.137.3", sub {
       file "/root/sbin/a1.pl",
       source => "/root/Rex/a1.pl";
    };
    [root@node01 Rex]# rex prepare01
    
    文件从本地的/root/Rex/a1.pl 上传到/root/sbin/a1.pl
    
    
    task "prepare01", "192.168.137.3", sub {
       file "/home/mqm/xbin/test.sh",
       source => "/root/Rex/test.sh",
       mode => 755,  
       owner  => "mqm",  
       group  => "mqm";
       my $output = run "/home/mqm/xbin/test.sh";  
       say $output;  
    
    };
    
    上传文件,执行命令
    
    node2:/home/mqm/xbin#ls -ltr
    total 33548
    -rw-r--r-- 1 mqm mqm 34344960 Mar 28  2017 mqm.tar
    drwxrwxr-x 3 mqm mqm     4096 Aug 24 22:02 mqm
    -rwxr-xr-x 1 mqm mqm       35 Sep 12 02:41 test.sh
    
    权限为755 数组为mqm:mqm
    
    
    task "prepare01", "192.168.137.3", sub {
       file "/home/mqm/xbin/test.sh",
       source => "/root/Rex/test.sh",
       mode => 700,  
       owner  => "mqm",  
       group  => "mqm";
       my $output = run "/home/mqm/xbin/test.sh";  
       say $output;  
    
    };
    
    node2:/home/mqm/xbin#ls -ltr
    total 33548
    -rw-r--r-- 1 mqm mqm 34344960 Mar 28  2017 mqm.tar
    drwxrwxr-x 3 mqm mqm     4096 Aug 24 22:02 mqm
    -rwx------ 1 mqm mqm       35 Sep 12 02:41 test.sh
    

  • 相关阅读:
    ie6下使PNG背景图片透明的方法
    CSS图片转换成模糊(毛玻璃)效果兼容版
    对象Object下的属性和方法
    Collection 回顾
    Java IO学习笔记:File类
    Android开发之Instrumentation(自动化测试)
    Android开发之ActivityManager
    Android开发之WindowManager详解
    在Intel® Galileo Gen 2开发板上运行Debian操作系统
    VS2008下安装与配置DirectShow SDK 9.0
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349493.html
Copyright © 2011-2022 走看看