Skip to content

Commit

Permalink
Add support for wildcards in tail, escapeshellargs
Browse files Browse the repository at this point in the history
  • Loading branch information
withaspark committed Aug 18, 2019
1 parent 427fd81 commit f9abc6a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/withaspark/LogAggregator/helpers.php
Expand Up @@ -50,7 +50,7 @@ function pull(string $output_dir = '/home/logging/logs'): void
{
list($hosts, $groups) = parse('config.php');

$output_dir = rtrim($output_dir ?: '/home/logging/logs', '/');
$output_dir = rtrim($output_dir, '/');
if (! is_writable($output_dir)) {
fprintf(STDERR, "\nERROR: Unable to write to output directory %s\n\nCreate or make writeable by current user.\n", $output_dir);
exit(1);
Expand Down Expand Up @@ -79,16 +79,16 @@ function pull(string $output_dir = '/home/logging/logs'): void
echo sprintf(
'echo \'[%s%%] Fetching %s from %s ...\'',
str_pad(number_format(($count - 1) / $total * 100, 0), 3, ' ', STR_PAD_LEFT),
$log,
$host->host
escapeshellarg($log),
escapeshellarg($host->host)
) . "\n";
echo sprintf(
'scp -P %d "%s@%s:%s" "%s"',
'scp -P %d %s@%s:%s %s',
$host->port,
$host->user,
$host->host,
$log,
$target
escapeshellarg($host->user),
escapeshellarg($host->host),
escapeshellarg($log),
escapeshellarg($target)
) . "\n";
}
}
Expand Down Expand Up @@ -122,7 +122,7 @@ function tail(): void
$host = $hosts[$h];

foreach ($logs as $log) {
echo sprintf('ssh -p %d "%s@%s" tail -n1 -f "%s" &', $host->port, $host->user, $host->host, $log) . "\n";
echo sprintf('ssh -p %d %s@%s tail -n1 -f %s &', $host->port, escapeshellarg($host->user), escapeshellarg($host->host), escapeshellarg($log)) . "\n";
}
}
}
Expand Down

0 comments on commit f9abc6a

Please sign in to comment.