Permalink
Browse files

Ask ps for username (getpwuid wont work for remote servers).

Added --debug to print lines to STDERR.
  • Loading branch information...
1 parent f3bbdc7 commit 24db99616b6b266bc7b7e11a42023ba151cdfc35 @acaudwell committed Aug 9, 2010
Showing with 13 additions and 7 deletions.
  1. +13 −7 scripts/gource-ps.pl
View
20 scripts/gource-ps.pl
@@ -8,9 +8,16 @@
use strict;
use warnings;
+use Getopt::Long qw(GetOptions);
#use Data::Dumper;
+my %opt = ();
+
+if(!GetOptions(\%opt, 'debug|d')) {
+ die("usage: gource-ps.pl [[USER\@]SERVER] | gource --log-format custom - ...\n");
+}
+
my $windows = $^O =~ /win32|msys/i;
if($windows) {
@@ -34,7 +41,7 @@
sub _proc_list {
- my $ps_command = 'ps axo pid,ppid,uid,time,comm';
+ my $ps_command = 'ps axo pid,ppid,user,time,comm';
my @pslist = $server ? `ssh $user\@$server "$ps_command"` : `$ps_command`;
@@ -51,13 +58,10 @@ sub _proc_list {
#build process tree
foreach my $line (@pslist) {
$line =~ s/^\s+//;
-
- my ($pid, $ppid, $uid, $time, @command) = split(/\s+/, $line);
-
- my $username = (getpwuid($uid))[0] or next;
- my $command = join(' ', @command) || '';
+ my ($pid, $ppid, $username, $time, @command) = split(/\s+/, $line);
+ my $command = join(' ', @command) || '';
$command =~ s{^.+/}{}g;
my $proc;
@@ -168,7 +172,9 @@ sub _make_command_path {
my $proc = $process{$pid};
if($proc->{status}) {
- print join('|', $current_time, $proc->{username}, $proc->{status}, _make_command_path($proc)), "\n"
+ my $output_line = join('|', $current_time, $proc->{username}, $proc->{status}, _make_command_path($proc)). "\n";
+ print $output_line;
+ print STDERR $output_line if $opt{debug};
}
#delete if not seen next time

0 comments on commit 24db996

Please sign in to comment.