#!/usr/bin/perl # Usage: # # Start a screen, ssh forward to tov port 3009, run this script. # Here's how to do that: # # wget http://retout.uwcs.co.uk/pogobot/uptime.perl # mv uptime.perl uptime.pl # screen # ssh -L 3009:localhost:3009 user@uwcs.co.uk # [Ctrl-A Ctrl-C] # ./uptime.pl # [Ctrl-A Shift-D Shift-D] # exit # use warnings; use strict; use IO::Socket::INET; # Expect Windows line endings from the core, for now. $/ = "\r\n"; my $socket = IO::Socket::INET->new( PeerAddr => 'localhost', PeerPort => 3009, Proto => 'tcp', ) or die "Couldn't open socket: $!"; my $cmd = 'som'; print "Registering $cmd.\n"; print $socket "REG $cmd\n"; while (<$socket>) { chomp; print "Received $_\n"; next unless (/^$cmd/); my $reply = uptime(); # Put the reply after the second field, removing the first field. s/^([^\t]*\t)([^\t]*)/$2 $reply/ || next; print "Saying", $_, "\n"; print $socket $_, "\n"; } sub uptime { open(UPTIME, "uptime|"); my $uptime = ; close UPTIME; return "$cmd: $uptime"; }