/usr/bin/oarprint is in oar-common 2.5.4-2+deb8u1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | #!/usr/bin/perl -w
# $Id$
# Simple Perl script to parse, sort and format a job resource properties file
#
use strict;
use warnings;
use Data::Dumper;
use Getopt::Long;
################################################################################
## Global variables (parameters)
my $key;
my $input=$ENV{OAR_RESOURCE_PROPERTIES_FILE};
my $fmt="%";
my $properties;
my $comma=",";
my $replace="%";
my $list;
my @properties_list;
################################################################################
## Option parsing
Getopt::Long::Configure ("gnu_getopt");
GetOptions(
"file|f=s" => \$input,
"format|F=s" => \$fmt,
"properties|P=s" => \$properties,
"comma|C=s" => \$comma,
"token|T=s" => \$replace,
"list|l" => \$list,
"help|h" => sub {usage(); exit(0);}
) or exit(1);
################################################################################
## usage()
sub usage() {
print STDERR <<EOF;
Usage: oarprint [options] <key property name>
Print a sorted output of the resources of a job with regard to a key property,
with a customisable format.
Options:
-f <file> input file, default: \$OAR_RESOURCE_PROPERTIES_FILE
-P <properties> property to display separated by commas, default: key property
-F <format> customised output format, default: "%"
-T <string> substitution token in the format string, default: %
-C <separator> separator when displaying lists, default: ,
-l list available properties and exit
-h print this help and exit
Examples:
On the job connection node (where \$OAR_RESOURCE_PROPERTIES_FILE is defined):
> oarprint host -P host,cpu,core -F "host: % cpu: % core: %" -C+
On the submission frontend:
> oarstat -j 42 -p | oarprint core -P host,cpuset,mem -F "%[%] (%)" -f -
EOF
}
################################################################################
## init_resource()
sub init_resources {
my $fh;
if (not defined($input)) {
die "$0: no input data available\n";
}
if ($input eq "-") {
$fh = \*STDIN;
} else {
open($fh, "< $input") or die "$0: $!\n";
}
my @T;
while (<$fh>) {
chomp;
s/ = / => /g;
push @T,"{ $_ }";
}
if ($input ne "-") {
close $fh;
}
my $res = eval("[".join(',',@T)."];");
return $res;
}
################################################################################
## list_properties()
sub list_properties {
my $resources=shift;
print "List of properties:\n";
print join(", ",(keys %{$resources->[0]}))."\n";
}
################################################################################
## print_output()
sub print_output {
my $resources=shift;
my $property=shift;
# build a hash tree sorted on unique values of the key property
my $h = {};
foreach my $r (@$resources) {;
exists ($r->{$property}) or die "$0: Unknown property '$property'\n";
my $v = $r->{$property};
for my $o (@properties_list) {
exists ($r->{$o}) or die "$0: Unknown property '$o'\n";
$h->{$v}->{$o}->{$r->{$o}} = undef;
}
}
#print Dumper($h)."\n";
#print data using the specified format
foreach my $v (values %$h) {
my @f = split($replace,$fmt);
my $i=0;
foreach my $o (@properties_list) {
if ($#f < 0) {
$i++ and print " ";
} else {
print shift(@f);
}
print join($comma,keys(%{$v->{$o}}));
}
if ($#f >= 0) {
print shift(@f);
}
print "\n";
}
}
################################################################################
## Main
my $resources = init_resources();
if (defined($list)) {
list_properties($resources);
} else {
$key = shift;
if (not defined($key)) {
die "$0: Need a property name\n";
}
if (defined($properties)) {
@properties_list = split(/\s*,\s*/,$properties);
}
if ($#properties_list < 0) {
@properties_list = ($key);
}
print_output($resources,$key);
}
|