Right, I've already tried this, and I've lost a substantial amount of hair. If some kind Perl-programming soul out there could help me, I'm sure I could ask Santa to leave you some cookies this Christmas.
Here's what I want the daemon to do:
@hosts = ('site1.com','site2.com');
&WriteToLog('STARTED');
for(;;){
foreach $host (@hosts) {
$socket = IO::Socket::INET->new("$host:80");
if (!$socket) {
&WriteToLog("HOST DOWN: $host");
exec("curl -u USERNAME:PASSWORD -d status=\"$host is DOWN\" http://twitter.com/statuses/update.json 1>/dev/null 2>/dev/null");
}else{
close($socket);
}
}
sleep(60);
}
&WriteToLog('STOPPED');
sub WriteToLog {
my($msg) = @_;
@months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
@weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
$year = 1900 + $yearOffset;
$theTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year";
open (MYFILE, '>> /etc/twitter/monitor.log');
print MYFILE "$theTime $msg\n";
close (MYFILE);
}
- @hosts = ('site1.com','site2.com');
- &WriteToLog('STARTED');
- for(;;){
- foreach $host (@hosts) {
- $socket = IO::Socket::INET->new("$host:80");
- if (!$socket) {
- &WriteToLog("HOST DOWN: $host");
- exec("curl -u USERNAME:PASSWORD -d status=\"$host is DOWN\" http://twitter.com/statuses/update.json 1>/dev/null 2>/dev/null");
- }else{
- close($socket);
- }
- }
- sleep(60);
- }
- &WriteToLog('STOPPED');
- sub WriteToLog {
- my($msg) = @_;
- @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
- @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
- ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
- $year = 1900 + $yearOffset;
- $theTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year";
- open (MYFILE, '>> /etc/twitter/monitor.log');
- print MYFILE "$theTime $msg\n";
- close (MYFILE);
- }
Much obliged to those that save my remaining sanity.