From e03ff8bb7a02a6fcc1a38932b152d671b99ec77f Mon Sep 17 00:00:00 2001
From: Mac Newbold <newbold@flux.utah.edu>
Date: Tue, 18 Jun 2002 15:23:33 +0000
Subject: [PATCH] Commit proper sorting I added weeks ago. (Stolen from
 snmpit_lib.pm)

---
 sensors/slothd/sdisrunning.in | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/sensors/slothd/sdisrunning.in b/sensors/slothd/sdisrunning.in
index d403b2a922..7f13ea95bc 100755
--- a/sensors/slothd/sdisrunning.in
+++ b/sensors/slothd/sdisrunning.in
@@ -52,9 +52,32 @@ order by pid,eid,node_id");
     }
 }
 
-sub pcnum { substr($a,2) <=> substr($b,2) }
+# Stolen from snmpit_lib.pm:
+#
+# Used to sort a set of nodes in testbed order (ie. pc2 < pc10)
+sub tbsort { 
+    my ($a,$b) = @_;
+    $a =~ /^([a-z]*)([0-9]*):?([0-9]*)/;
+    my $a_let = ($1 || "");
+    my $a_num = ($2 || 0);
+    my $a_num2 = ($3 || 0);
+    $b =~ /^([a-z]*)([0-9]*):?([0-9]*)/;
+    my $b_let = ($1 || "");
+    my $b_num = ($2 || 0);
+    my $b_num2 = ($3 || 0);
+    if ($a_let eq $b_let) {
+        if ($a_num == $b_num) {
+            return $a_num2 <=> $b_num2;
+        } else {
+            return $a_num <=> $b_num;
+        }
+    } else {
+        return $a_let cmp $b_let;
+    }
+    return 0;
+}
 
-foreach my $n (sort pcnum @nodes) {
+foreach my $n (sort {tbsort($a,$b)} @nodes) {
     print "checking slothd on $n: ";
     #print "\n"; next;
     print check($n);
-- 
GitLab