[root@yyjk rex]#cat Rexfile
use Rex -feature => ['1.0'];
use Rex::Misc::ShellBlock;
use Rex::Misc::PerlBlock;
use Rex::Misc::GetIpList qw(getlinuxlist getaixlist getwindowslist);
use Rex::Misc::GetCron  qw(getcron);
use Rex::Misc::InputSystemInfo qw(inputaix inputlinux);
use Rex::Misc::GetHardwareInfo qw(getlinuxhardinfo getaixhardinfo);
use Rex::Misc::ExecWindows qw(execwindowcmd);
use Encode;
use Net::OpenSSH;
user "root";
private_key "/root/.ssh/id_rsa";
public_key "/root/.ssh/id_rsa.pub";
key_auth;
parallelism(20);
#parallelism 'max';


  my @linux=getlinuxlist();
  my @aix=getaixlist();
  my @windows=getwindowslist();
  say @windows;
  group linux =>@linux;
  group aix =>@aix;
  group windows=>@windows;
  my @allservers=(@linux,@aix);
  group allservers=>@allservers;
  foreach (@linux){
  if (! -d "/data01/oracle/$_/"){
       mkdir "/data01/oracle/$_/"
      };
   };
  foreach (@aix){
  if (! -d "/data01/oracle/$_/"){
       mkdir "/data01/oracle/$_/"
      };
   };

    foreach (@windows){
  if (! -d "/data01/oracle/$_/"){
       mkdir "/data01/oracle/$_/"
      };
   };

  task 'mytask1', group => "linux", sub {
  my $current_server = connection->server;
    $current_server =~s/^\s+//;
  $current_server =~s/ +$//;
  say $current_server;
  my $output1 = run "netstat -nap";
  open A,">/data01/oracle/$current_server/${current_server}_port.txt";
  print A $output1."\n";
  close A;
  my $output2 = run "ps -ef";
  open B,">/data01/oracle/$current_server/${current_server}_ps.txt";
  print B $output2."\n";
  close B;
  #inputlinux($current_server);
};


  task 'mytask2', group => "aix", sub {
  my $current_server = connection->server;
    $current_server =~s/^\s+//;
  $current_server =~s/ +$//;
  say $current_server;
  my $output1 = run "netstat -na";
  open A,">/data01/oracle/$current_server/${current_server}_port.txt";
  print A $output1."\n";
  close A;
  my $output2 = run "ps -ef";
  open B,">/data01/oracle/$current_server/${current_server}_ps.txt";
  print B $output2."\n";
  close B;
  #inputaix($current_server);
};
  task 'mytask3', group => "allservers", sub {
  my $current_server = connection->server;
  my @crons = cron list => "root";
  my $r=\@crons;
   #print Dumper($r);
   foreach (@{$r}){
      say $_->{'line'};
      getcron($current_server,'root',$_->{'line'});
   };
};
  task 'mytask4',group=>"windows",sub {
  my $current_server = connection->server;
  $current_server =~s/^\s+//;
  $current_server =~s/ +$//;
  my $output= execwindowcmd($current_server,'tasklist');
  my $tasklist= encode("utf8",decode("gbk","$output"));
  open A,">/data01/oracle/$current_server/${current_server}_ps.txt";
  print A $tasklist."\n";
  close A;
  my $output= execwindowcmd($current_server,'netstat -nao');
  my $port= encode("utf8",decode("gbk","$output"));
  open B,">/data01/oracle/$current_server/${current_server}_port.txt";
  print B $port."\n";
  close B;
};


  task 'mytasktest',"10.3.245.2",sub {
  my $current_server = connection->server;
  say $current_server;
  my $output= execwindowcmd($current_server,'tasklist');
  my $tasklist= encode("utf8",decode("gbk","$output"));
  open A,">/data01/oracle/$current_server/${current_server}_ps.txt";
  print A $tasklist."\n";
  close A;
  my $output= execwindowcmd($current_server,'netstat -nao');
  my $port= encode("utf8",decode("gbk","$output"));
  open B,">/data01/oracle/$current_server/${current_server}_port.txt";
  print B $port."\n";
  close B;
};

 task "get-os", group=>"linux", sub {
   my %hash= get_system_information();
   print %hash;
   my $operating_system= $hash{'operating_system'};
   my $operatingsystemrelease= $hash{'operatingsystemrelease'};
   my $hostname= $hash{'hostname'};
   my $memory_total= $hash{'memory_total'};
   my $swap_total= $hash{'swap_total'};
   my $manufacturer=$hash{'manufacturer'};
   my $current_server = connection->server;
  getlinuxhardinfo($current_server,$operating_system, $operatingsystemrelease, $hostname,$memory_total,$swap_total,$manufacturer);


 };

 task "check_oracle","20.5.101.31",sub {
    my $output=run "perl /root/sbin/oracle/test.pl";
    say $output;
};



[root@yyjk rex]#rex check_oracle
$hostsql=select distinct trim(ipaddr)  from tlcb_mon_device where devicetype='General Linux' and  hasdeployed='3'
$hostsql=select distinct trim(ipaddr)  from tlcb_mon_device where DEVICETYPE='IBM AIX' and HASDEPLOYED='3'
$hostsql=select distinct trim(ipaddr)  from tlcb_mon_device where devicetype='Microsoft Windows'  and hasdeployed='3'
10.2.228.920.5.102.1
[2018-12-21 10:21:36] WARN - Please use only the following characters for task names:
[2018-12-21 10:21:36] WARN -   A-Z, a-z, 0-9 and _
[2018-12-21 10:21:36] WARN - Also the task should start with A-Z or a-z
[2018-12-21 10:21:36] WARN - You can disable this warning by setting feature flag: disable_taskname_warning
[2018-12-21 10:21:36] INFO - Running task check_oracle on 20.5.101.31
ddad2313
$VAR1 = {
          'auto_die' => undef
        };



[root@yyjk rex]#rex check_oracle
[2018-12-21 10:21:49] INFO - Rexfile is in use by 11808.
[root@yyjk rex]#

 

12-24 18:37