#!/usr/bin/perl -w # # ss and sss # John Simpson 2005-03-26 # # human-friendly listing of daemontools service status reports. # # when run as "ss", only shows the services. when run as "sss", also shows # the status of the "log" services attached to each service. # # normally installed in /root/bin/ss, with a symlink or hardlink called "sss" # pointing to it (so that both commands work from the same script.) # ############################################################################### # # Copyright (C) 2005 John Simpson. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # or visit http://www.gnu.org/licenses/gpl.txt # ############################################################################### require 5.003 ; use strict ; sub hms($) { my $seconds = shift ; my ( $days , $hours , $minutes ) ; my $rv = "" ; if ( "" eq $seconds ) { return "" ; } $days = int ( $seconds / 86400 ) ; $seconds -= 86400 * $days ; $hours = int ( $seconds / 3600 ) ; $seconds -= 3600 * $hours ; $minutes = int ( $seconds / 60 ) ; $seconds -= 60 * $minutes ; if ( $days > 1 ) { return sprintf ( "%d days %2d:%02d:%02d" , $days , $hours , $minutes , $seconds ) ; } if ( $days > 0 ) { return sprintf ( "%d day %2d:%02d:%02d" , $days , $hours , $minutes , $seconds ) ; } elsif ( $hours > 0 ) { return sprintf ( "%d:%02d:%02d" , $hours , $minutes , $seconds ) ; } else { return sprintf ( "%d:%02d" , $minutes , $seconds ) ; } } ############################################################################### ############################################################################### ############################################################################### my $text = `svstat /service/*` ; if ( $0 =~ /sss$/ ) { $text .= "\n" . `svstat /service/*/log` ; } my $clen = 1 ; for my $line ( split ( /\n/ , $text ) ) { my ( $a , $b ) = split ( /\:/ , $line ) ; next unless ( defined $b ) ; if ( length ( $a ) > $clen ) { $clen = length ( $a ) ; } } for my $line ( split ( /\n/ , $text ) ) { my ( $a , $b ) = split ( /\:/ , $line ) ; if ( defined $b ) { $b =~ s/(\d+) seconds// ; my $t = hms ( $1 || "" ) ; printf "%-${clen}s %-20s %18s\n" , $a , $b , $t ; } else { print "$line\n" ; } }