#! /usr/bin/perl # # usage: get_workdisk_usage (must be on one of the farm machines) # # date: 06/06/06 # # by: Jaideep Singh # # description: gets disk usage information about the workdisks for halla # outputs the amount of free space, total space, pct used, # mount point, and experiments assigned to that work disk # # output: # # Free(G) Tot(G) % Use Disk Experiments (as of Tue Aug 1 12:00:30 EDT 2006) # # 0.00 245 100% /w/work2806 e94107 and that's it. # 10.08 252 96% /w/work2804 gdh-2 and that's it. # 18.32 229 92% /w/work1705 e01001 and that's it. # 20.61 229 91% /w/work1703 gdh and that's it. # # getting list of directories $raw = qx(ls /work/halla/); @list = split /\s+/ , $raw; # getting disk information for each directory %workdisks = (); foreach $dir (@list) { $result = qx(df -h /work/halla/$dir); @lines = split /\n/ , $result; @data = split /\s+/ , $lines[2]; $total = $data[1]; $used = $data[2]; $free = $data[3]; $pct_use = $data[4]; $mount_point = $data[5]; $workdisks{$mount_point}{"totalG"} = $total; $workdisks{$mount_point}{"pctuse"} = $pct_use; $workdisks{$mount_point}{"explist"} .= $dir." and "; } # calculating and formatting output for each mount_point $mount_point = ""; $date = qx(date); chomp($date); print "\nFree(G)\tTot(G)\t\% Use\tDisk\t\t\tExperiments (as of $date)\n"; for $mount_point (sort keys %workdisks) { $totalG = $workdisks{$mount_point}{"totalG"}; $pctuse_s = $workdisks{$mount_point}{"pctuse"}; $explist = $workdisks{$mount_point}{"explist"}; $total = 0.0; if ($totalG =~ /(\d+)G/) { $total = $1; } $pctuse = 0.0; if ($pctuse_s =~ /([0123456789\.]+)\%/) { $pctuse = $1; } $free = (1.0-$pctuse/100.0)*$total; $mnt_pt_len = length($mount_point); $num_tab = 0; if ($mnt_pt_len < 8) { $num_tab = 3; } elsif ($mnt_pt_len < 12) { $num_tab = 2; } elsif ($mn_pt_len < 17) { $num_tab = 1; } $this_out = sprintf("%.2f",$free); $this_out .= "\t".$total."\t".$pctuse_s."\t".$mount_point; for ($count = 1 ; $count <= $num_tab ; $count++) { $this_out .= "\t"; } $this_out .= $explist."that\'s it.\n"; if (!defined($out)) { $out = $this_out; } else { $out .= $this_out; } } # sorting list by amount of free space and outputting $sorted_list = qx(echo "$out" | sort -nk1); print "$sorted_list\n";