怎么检查远程运行命令的退出值?
Rex 会把远程运行的 run 或者 shell_block 语句的退出值存入 $? 变量。
task "task2", group=>"myservers", sub {
my $output = run "df -h";
say '----------------------';
say $?;
say '----------------------';
say $output;
};
[root@node01 Rex]# rex task2
[2017-04-30 14:09:10] INFO - Running task task2 on 192.168.137.3
----------------------
0
----------------------
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 19G 11G 7.1G 60% /
tmpfs 497M 0 497M 0% /dev/shm
/dev/sda1 194M 29M 155M 16% /boot
[2017-04-30 14:09:22] INFO - All tasks successful on all hosts
task "task2", group=>"myservers", sub {
my $output = run "ld";
say '----------------------';
say $?;
say '----------------------';
say $output;
};
[root@node01 Rex]# rex task2
[2017-04-30 14:09:55] INFO - Running task task2 on 192.168.137.3
----------------------
1
----------------------