]> granicus.if.org Git - pgbadger/commitdiff
Fix remote paths when using SSH.
authorLuca Ferrari <fluca1978@gmail.com>
Fri, 24 May 2019 12:04:41 +0000 (14:04 +0200)
committerLuca Ferrari <fluca1978@gmail.com>
Fri, 24 May 2019 12:04:41 +0000 (14:04 +0200)
When specifying a directory instead of a remote file, the program aborts
with a message like:

% pgbadger  ssh://postgres@pghost//postgres/data/log/
FATAL: can't get size of remote file,
       please check what's going wrong with command:
       ssh postgres@pghost "ls -l postgresql-Fri.log"

The problem is that the set_file_list function does not include the path
on the remote host, managing each file path as relative. Therefore
now there is an addition of $dirs before pushing the path to the @lfiles array.
However, this is due only when there is a directory, that is when the number
of remote files on each function invocation is not equal at one.

pgbadger

index be27268b70f1ef06d5e93aafd7ce905282503dd7..e0a7e7ee4ab8aa5e98338663c16e89a313fac821 100755 (executable)
--- a/pgbadger
+++ b/pgbadger
@@ -2106,9 +2106,10 @@ sub set_file_list
                                my($filename, $dirs, $suffix) = fileparse($file);
                                &logmsg('DEBUG', "Looking for remote filename using command: $ssh $host_info \"ls '$dirs'$filename\"");
                                my @rfiles = `$ssh $host_info "ls '$dirs'$filename"`;
+        $dirs = '' if ( @rfiles <= 1 );
                                foreach my $f (@rfiles)
                                {
-                                       push(@lfiles, "ssh://$host_info/$f$fmt");
+                                       push(@lfiles, "ssh://$host_info/$dirs$f$fmt");
                                }
                        }
                        $empty_files = 0;