Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # NOTE: We don't use Anvil::Tools to keep overhead low and to keep this agent independent as possible.
- use strict;
- use warnings;
- use Data::Dumper;
- # Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete.
- $| = 1;
- # Log file
- our $log_file = "/var/log/anvil.log";
- open (my $log_fh, ">>", $log_file) or die "Failed to open: [".$log_file."] for writing. The error was: ".$!."\n";
- $log_fh->autoflush(1);
- binmode($log_fh, ':encoding(utf-8)');
- foreach my $key (sort {$a cmp $b} keys %ENV)
- {
- print $log_fh "Environment: [".$key."] -> [".$ENV{$key}."]\n";
- }
- my $output = "";
- my $call_string = "/usr/bin/strace -o /tmp/virsh.bad -ff -tt /usr/bin/virsh list --all 2>&1; |";
- print $log_fh "Current UID: [".$<."], current EUID: [".$>."]\n";
- print $log_fh "Current GID: [".$(."], current EGID: [".$(."]\n";
- print $log_fh "Calling: [".$call_string."]\n";
- open (my $file_handle, $call_string) or die "Print: Failed to call: [".$call_string."]\n";
- while(<$file_handle>)
- {
- chomp;
- my $line = $_;
- $line =~ s/\n$//;
- $line =~ s/\r$//;
- print $log_fh "line: [".$line."]\n";
- $output .= $line."\n";
- }
- close $file_handle;
- chomp($output);
- $output =~ s/\n$//s;
- print $log_fh "Output:
- ========
- ".$output."
- ========
- ";
- exit(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement