#!/usr/bin/perl -w #use strict; my $VERSION = '0.80.01'; use Socket; &main(); sub main () { unless (&open_TCP(F, 'localhost', 13000)) { print STDERR 'Error'; exit(1); } print F "GET /status.txt?password=foo HTTP/1.0\n\n"; if ($ARGV[0] eq 'smsc-conn') { open(MEM, "<.hc_smsc_conn.csv"); my @mem = split /\|/, ; my $laststat = ; close MEM; my %memo = (); foreach (@mem) { my ($key, $val) = split /\=/; chomp $key; $memo{$key} = $val if $key; # print "[mem] $key = $val\n" if $key; } while() { last if /^SMSC connections/; } while() { chomp; next unless $_; s/^ *(.+)$/$1/; # trim leading spaces (my $dummy = $_) =~ s/.+ \((.+)\)$/$1/; my @elems = split /,/, $dummy; my %hash = (); foreach (@elems) { s/^ *(.+)$/$1/; my ($key, $val) = split / /; $val =~ s/s$//; $hash{$key} = $val; } open(MEM, ">.hc_smsc_conn.csv") or print STDERR $!; foreach (keys %hash) { # print "$_: $hash{$_} vs. $memo{$_}\n"; print MEM "$_=", $hash{$_}, '|'; } print MEM "\n$_\n"; close MEM; print "$_\n"; if ($hash{'online'} < $memo{'online'}) { print STDERR "*** ERR ", &tstamp(), " Lost Connection! Last: $laststat\n"; } } } while() { print; } close F; } sub open_TCP (@) { my ($FS, $dest, $port) = @_; my $proto = getprotobyname('tcp'); socket($FS, PF_INET, SOCK_STREAM, $proto); my $sin = sockaddr_in($port, inet_aton($dest)); connect($FS, $sin) || return undef; my $old_fh = select($FS); $| = 1; select($old_fh); 1; } sub tstamp() { my ($y, $m, $d, $H, $M, $S) = (localtime)[5,4,3,2,1,0]; $y += 1900; $m++; sprintf("%d-%02d-%02d %02d:%02d:%02d", $y, $m, $d, $H, $M, $S); }