显示任务执行信息,去掉过程和错误信息
rex -qw uptime
把执行结果存到文件中
rex -qw uptime | tee -a info.log
指定主机执行
rex -qw -H ‘192.168.1.1 192.168.1.2’ uptime
显示主机ip的
my $output = run “uptime”;
say connection->server.$output;
多进程
parallelism n;
sudo执行:
sudo TRUE;
sudo_password ‘ttrttr’;
指定分组执行 temp:
rex -qw -G temp $task
列出命令项目 rex -h
列出任务和分组列表 rex -T
通过文件执行定义任务
rex -qw creatuser -f usermange
任务sample
添加sudo
task “addsudo”,group =>”all”, sub {
append_if_no_such_line “/etc/sudoers”, “yy ALL=(ALL) ALL”;
say connection->server.” Sudo add success!”;
};
删除用户
task “addsudo”,group =>”all”, sub {
append_if_no_such_line “/etc/sudoers”, “yy ALL=(ALL) ALL”;
say connection->server.” Sudo add success!”;
};
创建或者修改用户
task “create-user”,group => “all”, sub {
say connection->server.” begin create”;
create_user “yy”,
password => ‘yy123’;
create_user “xx”,
password => ‘xx123’;
say connection->server.” done!”;
};
启用ini文件定义分组:
—————-
use Rex -base;
use Rex::Group::Lookup::INI;
use Rex::Commands::User;
user “yy”;
password ‘ttrttr’;
pass_auth;
port 65522;
groups_file “list.ini”;
parallelism 10;
ini文件
list.ini
[all]
192.168.1.1
192.168.1.2
..
———-
———-
服务列表
task “list”, group => “all”, sub {
say connection->server;
};
———–