a little more verbose error message to point out the issue if vsys fails to execute...
[vsys.git] / factory / pl-ps
1 #!/usr/bin/perl
2 use strict;
3
4 ###############################################
5 # pl-ps for slicestat by KyoungSoo Park
6 ###############################################
7
8 my %slice_id;
9 my %slice;
10
11 open THIS_PIPE, "/bin/awk -F: \'{print \$1, \$3}\' /etc/passwd |";
12 while(<THIS_PIPE>) {
13    if (/(.+)\s+(\d+)/) {
14        $slice_id{$1} = $2;
15        $slice{$2} = $1;
16    }
17 }
18 close THIS_PIPE;
19
20 open THIS_PIPE, "/usr/sbin/vps -eo pid,user | sed 1d | awk \'{print \$1, \$2}\' | sort -k 2 |";
21 while(<THIS_PIPE>) {
22    if (/(\d+)\s+(.+)$/) {
23        my $pid = $1;
24        my ($id, $sl);
25
26        if (defined($slice_id{$2})) {
27            $id = $slice_id{$2};
28            $sl = $2;
29        } else {
30            $id = $2;
31            $sl = $slice{$2};
32        }
33        print sprintf("%s %s %s\n", $id, $sl, $pid);
34    }
35 }
36 close THIS_PIPE;