summaryrefslogtreecommitdiff
path: root/eg/myrup
blob: f7d64dbd2f484776aac6c2dab4b82131e2e4522a (plain)
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
#!/usr/bin/perl

# $Header: myrup,v 3.0 89/10/18 15:15:06 lwall Locked $

# This was a customization of ruptime requested by someone here who wanted
# to be able to find the least loaded machine easily.  It uses the
# /etc/ghosts file that's defined for gsh and gcp to prune down the
# number of entries to those hosts we have administrative control over.

print "node    load (u)\n------- --------\n";

open(ghosts,'/etc/ghosts') || die "Can't open /etc/ghosts: $!";
line: while (<ghosts>) {
    next line if /^#/;
    next line if /^$/;
    next line if /=/;
    ($host) = split;
    $wanted{$host} = 1;
}

open(ruptime,'ruptime|') || die "Can't run ruptime: $!";
open(sort,'|sort +1n');

while (<ruptime>) {
    ($host,$upness,$foo,$users,$foo,$foo,$load) = split(/[\s,]+/);
    if ($wanted{$host} && $upness eq 'up') {
	printf sort "%s\t%s (%d)\n", $host, $load, $users;
    }
}