* Created anvil-file-details that is (meant to be) called by anvil-file-details on a remote machine.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 6 years ago
parent 48d9f70c87
commit e8afd2efe4
  1. 3
      Anvil/Tools/Database.pm
  2. 1
      share/words.xml
  3. 92
      tools/anvil-file-details
  4. 4
      tools/anvil-manage-files

@ -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();
}

@ -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!#]
</key>
<key name="log_0275">Gathering data for: [#!variable!file!#]:</key>
<!-- Test words. Do NOT change unless you update 't/Words.t' or tests will needlessly fail. -->
<key name="t_0000">Test</key>

@ -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 <full_path>' 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 </path/to/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});

@ -406,6 +406,10 @@ AND
's2:name' => $name,
's3:ip' => $ip,
}});
my $output = $anvil->Remote->call({
shell_call => "",
});
}
}
}

Loading…
Cancel
Save