Advertisement
digimer

Untitled

Jan 11th, 2023
1,448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.30 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. foreach my $key (sort {$a cmp $b} keys %ENV)
  18. {
  19.     print $log_fh "Environment: [".$key."] -> [".$ENV{$key}."]\n";
  20. }
  21.  
  22. my $output      = "";
  23. my $call_string = "/usr/bin/strace -o /tmp/virsh.bad -ff -tt /usr/bin/virsh list --all 2>&1; |";
  24. print $log_fh "Current UID: [".$<."], current EUID: [".$>."]\n";
  25. print $log_fh "Current GID: [".$(."], current EGID: [".$(."]\n";
  26. print $log_fh "Calling: [".$call_string."]\n";
  27. open (my $file_handle, $call_string) or die "Print: Failed to call: [".$call_string."]\n";
  28. while(<$file_handle>)
  29. {
  30.     chomp;
  31.     my $line =  $_;
  32.        $line =~ s/\n$//;
  33.        $line =~ s/\r$//;
  34.     print $log_fh "line: [".$line."]\n";
  35.     $output .= $line."\n";
  36. }
  37. close $file_handle;
  38. chomp($output);
  39. $output =~ s/\n$//s;
  40.  
  41. print $log_fh "Output:
  42. ========
  43. ".$output."
  44. ========
  45. ";
  46.  
  47. exit(0);
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement