forked from pflanze/chj-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_vserver_all_ncontexts_do
executable file
·62 lines (48 loc) · 1.38 KB
/
_vserver_all_ncontexts_do
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl -w
#root@elvis root# ncontext --nid 1005 --migrate chcontext --ctx 1005 show_tcpconnections
#is the only thing that works. so..:
# Don Feb 8 15:26:03 CET 2007
(my $email='pflanze%gmx,ch')=~ tr/%,/@./;
use strict;
$0=~ /(.*?)([^\/]+)\z/s or die "?";
my ($mydir, $myname)=($1,$2);
sub usage {
print STDERR map{"$_\n"} @_ if @_;
print "$myname cmd ( cmd-arguments )
Run cmd in all (running) vservers' network and vserver contexts (but
in the host's filesystem context).
(Used by vshow_tcpconnections etc.)
Options:
-a|--all show all running vservers, even those without open connections
(Christian Jaeger <$email>)
";
exit @_ ? 1 : 0;
}
use Getopt::Long;
our $DEBUG=0;
our $opt_all;
if (@ARGV and $ARGV[0]=~ /^-/) {
GetOptions ("d|ebug"=> \$DEBUG,
"h|elp"=> sub{usage},
"a|ll"=> \$opt_all,
)
or exit 1;
usage unless @ARGV;
}
our @cmd=@ARGV;
use Chj::IO::Command;
use Chj::xperlfunc;
my $stat= Chj::IO::Command->new_sender ("vserver-stat");
$stat->xreadline =~ /^CTX/ or die "invalid output";
my $width= $ENV{COLUMNS}||100;
while (<$stat>) {
chomp;
if (my ($ctx,$name)= /^(\d+)\s+.*?(\w+)$/) {
next if $ctx == 0;
print "-- $name: ".("-"x($width-4-3-length($name)))."\n";
xxsystem "ncontext", "--nid", $ctx, "--migrate", "chcontext", "--ctx", $ctx, "--", @cmd;
#print "\n";
} else {
die "invalid output '$_'";
}
}