Advertisement
digimer

Untitled

Jan 10th, 2023
1,491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.03 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # NOTE: We don't use Anvil::Tools to keep overhead low and to keep this agent independent as possible.
  4. use strict;
  5. use warnings;
  6. use Data::Dumper;
  7.  
  8. # Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete.
  9. $| = 1;
  10.  
  11. # Log file
  12. our $log_file = "/var/log/anvil.log";
  13. open (my $log_fh, ">>", $log_file) or die "Failed to open: [".$log_file."] for writing. The error was: ".$!."\n";
  14. $log_fh->autoflush(1);
  15. binmode($log_fh, ':encoding(utf-8)');
  16.  
  17. my $output      = "";
  18. my $call_string = "/usr/bin/strace /usr/bin/virsh list --all 2>&1; |";
  19. print $log_fh "Calling: [".$call_string."]\n";
  20. open (my $file_handle, $call_string) or die "Print: Failed to call: [".$call_string."]\n";
  21. while(<$file_handle>)
  22. {
  23.     chomp;
  24.     my $line =  $_;
  25.        $line =~ s/\n$//;
  26.        $line =~ s/\r$//;
  27.     print $log_fh "line: [".$line."]\n";
  28.     $output .= $line."\n";
  29. }
  30. close $file_handle;
  31. chomp($output);
  32. $output =~ s/\n$//s;
  33.  
  34. print $log_fh "Output:
  35. ========
  36. ".$output."
  37. ========
  38. ";
  39.  
  40. exit(0);
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement