From e8afd2efe42b8cac6527c9dbcb368669fb10530b Mon Sep 17 00:00:00 2001 From: Digimer Date: Fri, 8 Mar 2019 00:27:30 -0500 Subject: [PATCH] * Created anvil-file-details that is (meant to be) called by anvil-file-details on a remote machine. Signed-off-by: Digimer --- Anvil/Tools/Database.pm | 3 +- share/words.xml | 1 + tools/anvil-file-details | 92 ++++++++++++++++++++++++++++++++++++++++ tools/anvil-manage-files | 4 ++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100755 tools/anvil-file-details diff --git a/Anvil/Tools/Database.pm b/Anvil/Tools/Database.pm index 294fc230..65097376 100644 --- a/Anvil/Tools/Database.pm +++ b/Anvil/Tools/Database.pm @@ -1283,8 +1283,9 @@ SELECT FROM notifications WHERE - notification_host_uuid = ".$anvil->Database->quote($job_host_uuid)." + notification_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)." ;"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); return(); } diff --git a/share/words.xml b/share/words.xml index afd5b91d..f30d4fec 100644 --- a/share/words.xml +++ b/share/words.xml @@ -578,6 +578,7 @@ The fingerprint of: [#!variable!machine!#] has changed! Updating it's entry in k - From: [#!variable!old_key!#] - To: . [#!variable!new_key!#] + Gathering data for: [#!variable!file!#]: Test diff --git a/tools/anvil-file-details b/tools/anvil-file-details new file mode 100755 index 00000000..ec570a63 --- /dev/null +++ b/tools/anvil-file-details @@ -0,0 +1,92 @@ +#!/usr/bin/perl +# +# All this does is stat a file and return the information in a parsable way. For this reason, translatable +# strings are not used. +# +# NOTE: This isn't comprehensive at all. It's mainly meant to be used when 'anvil-file-details' is looking on +# the hosts for a file it is missing. +# +# Exit codes; +# 0 = Normal exit or md5sum of this program changed and it exited to reload. +# 1 = '--file ' not used. +# 2 = File not found. +# + +use strict; +use warnings; +use Anvil::Tools; +use Data::Dumper; + +# Disable buffering +$| = 1; + +my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0]; +my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0]; +if (($running_directory =~ /^\./) && ($ENV{PWD})) +{ + $running_directory =~ s/^\./$ENV{PWD}/; +} + +my $anvil = Anvil::Tools->new(); +$anvil->Log->level({set => 2}); +$anvil->Log->secure({set => 1}); + +$anvil->data->{switches}{file} = ""; +$anvil->data->{switches}{'with-md5sum'} = ""; +$anvil->Get->switches; +$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + "switches::file" => $anvil->data->{switches}{file}, + "switches::with-md5sum" => $anvil->data->{switches}{'with-md5sum'}, +}}); + +my $file = $anvil->data->{switches}{file}; +if (not $file) +{ + print "[ Error ] - Not called with '--file '.\n"; + $anvil->nice_exit({exit_code => 1}); +} +elsif (not -e $file) +{ + print "[ Error ] - File: [".$file."] not found.\n"; + $anvil->nice_exit({exit_code => 1}); +} +else +{ + ### TODO: Should be -l -> lstat? + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0275", variables => { file => $file }}); + my @details = stat($file); + my $mode = $details[2]; + $mode = sprintf("04%o", $details[2] & 07777); + my $user_id = $details[4]; + my $group_id = $details[5]; + my $size = $details[7]; + my $mtime = $details[9]; + my $md5sum = "--"; + if ($anvil->data->{switches}{'with-md5sum'}) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0265", variables => { file => $file }}); + if ($size > (128 * (2 ** 20))) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0266", variables => { + size => $anvil->Convert->bytes_to_human_readable({'bytes' => $size}), + }}); + } + + # Update (or get) the md5sum. + $md5sum = $anvil->Get->md5sum({debug => 2, file => $file}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { md5sum => $md5sum }}); + } + + print "File: [".$file."] +size: [".$size."] +mode: [".$mode."] +uid: [".$user_id."] +gid: [".$group_id."] +mtime: [".$mtime."] +md5sum: [".$md5sum."]\n"; +} + + + +# We're done +$anvil->nice_exit({exit_code => 0}); diff --git a/tools/anvil-manage-files b/tools/anvil-manage-files index acc4e7fc..9ae3c320 100755 --- a/tools/anvil-manage-files +++ b/tools/anvil-manage-files @@ -406,6 +406,10 @@ AND 's2:name' => $name, 's3:ip' => $ip, }}); + + my $output = $anvil->Remote->call({ + shell_call => "", + }); } } }