# HG changeset patch # User Peter Gervai # Date 1399472625 -7200 # Node ID 464dea07deb86017f46968e1673459bbfbbeda5a # Parent c2cff30df6dc7fc7efa6cbe941814f9c3838e2e6 Add vzps replacements. diff -r c2cff30df6dc -r 464dea07deb8 add_vzps.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/add_vzps.pl Wed May 07 16:23:45 2014 +0200 @@ -0,0 +1,20 @@ +#!/usr/bin/perl +# +# (c)Peter Gervai, 2013 +# +# use: ps awxuf | add_vzps.pl +# + +while( <> ) { + my @cmd = split /\s+/; + my $pid = $cmd[1]; + if( -r "/proc/$pid/status" ) { + my $veid_line = qx( /bin/grep 'envID:' /proc/$pid/status ); + if( $veid_line =~ /envID:\s+(\d+)/ ) { + print $1, '; ', $_; + + } else { + print "SKIP $veid_line "; + } + } +} diff -r c2cff30df6dc -r 464dea07deb8 vz_ps.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vz_ps.pl Wed May 07 16:23:45 2014 +0200 @@ -0,0 +1,50 @@ +#!/usr/bin/perl +# $Id: vz_ps.pl,v a19295214a68 2013/10/29 15:31:42 grin $ +# (c) Petre Gervai, 2011-2013 +# Released under CreativeCommons Attribution-ShareAlike v3.0 unported +# CC-BY-SA-3.0-unp +# +# Show OpenVZ info using stock ps output instead of hacking it in +# + +use warnings; +use strict; +use IO::File; + +my $ps = "/bin/ps"; + +my $f; + +if( $#ARGV == 0 ) { + # use 'spawn ps' mode + $f = new IO::File 'ps ' . join(' ', @ARGV) . " |" or die $!; + +} else { + # get data on stdin + $f = IO::Handle->new_from_fd( fileno(STDIN), 'r' ); +} + +# get header +my $hdr = <$f>; +if( $hdr !~ /PID/ ) { + print "Error: ps header doesn't contain PID, it's something I cannot accept. I'm going.\n"; + exit 1; +} + +my $pos; +$hdr =~ s/^\s*(.+?)\s*$/$1/; # remove head/trail spc +my @head = split /\s+/, $hdr; +while( my ($i,$val) = each @head ) { + if( $val=~ /^PID$/ ) { + $pos = $i; + last; + } +} + +use Data::Dumper; +print Dumper( \@head, $pos ); +die; + +while( <$f> ) { + +}