次のコマンドとその出力が与えられます。
ssh -q $server 'df -hP /raj*
Size Used Avail Capacity Mounted On
200G 154G 44G 79% /raj_day
200G 154G 44G 49% /raj1_day
200G 154G 44G 39% /raj2_day
表形式に変換したいので、プレゼンテーションがうまくいくはずです。また、Capacityをソート順に表示したい。perlで私に何かヒントはありますか?
次のように私のスクリプト...
#############################################
#!/usr/local/bin/perl
# Use either -h or -k flag or leave it blank for default (-k)
# -h for human-readable size output
# -k for 1k-block output
$flag = "-h";
@df = `df $flag`;
print "Content-type: text/htmln\n";
print "<table border=2>\n";
print "<tr>\n";
print "<td><b>Filesystem</b></td>\n";
if ($flag eq "-h") {
print "<td><b>Size</b></td>\n";
}
else {
print "<td><b>1k-blocks</b></td>\n";
}
print "<td><b>Used</b></td>\n";
print "<td><b>Avail</b></td>\n";
print "<td><b>Capacity</b></td>\n";
print "<td><b>Mounted on</b></td>\n";
print "</tr>\n";
foreach $line (@df) {
next if ($line =~ /Filesystem/);
($fsystem,$blocks,$used,$avail,$capacity,$mounted) = split(/s+/,$line);
print "fsystem is $fsystem\n";
print "blocks is $blocks\n";
print "used is $used\n";
print "avail is $avail\n";
print "capacity is $capacity\n";
print "mounted is $mounted\n";
($number,$sign) = split(/%/,$capacity);
if ($number < 60) {
print "<tr bgcolor=green>\n";
}
elsif (($number >= 60) && ($number < 90)) {
print "<tr bgcolor=yellow>\n";
}
else {
print "<tr bgcolor=red>\n";
}
#
print "<td>$fsystem</td>\n";
print "<td>$blocks</td>\n";
print "<td>$used</td>\n";
print "<td>$avail</td>\n";
print "<td>$capacity</td>\n";
print "<td>$mounted</td>\n";
print "</tr>\n";
}
print "</table>\n";
次のような出力
Content-type: text/htmln Filesystem Size Used Avail Capacity Mounted on fsystem is /dev/ blocks is da3 95G
33G 58G 36% /used is avail is capacity ismounted is fsystem is tmpf blocks is
499M 88K 499M 1% /dev/ used is hmavail is capacity ismounted is fsystem is /dev/ blocks is da1
124M 39M 79M 33% /boot中古ですが利用できます容量は搭載されています