Escribir un demonio en Perl

  • jammer2552
  • Graduate
  • Graduate
  • Avatar de Usuario
  • Registrado: Jul 23, 2006
  • Mensajes: 139
  • Status: Offline

Nota Abril 19th, 2009, 7:51 pm

Derecho, Ive ya ha probado esto, y Ive perdido una cantidad considerable de pelo. Si algún tipo de programación Perl alma por ahí me podría ayudar, Im seguro de que podría pedir a Santa a dejar algunas galletas esta Navidad.

Heres lo que desea que el demonio que hacer:
Código: [ Select ]
@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);
}
  1. @hosts = ('site1.com','site2.com');
  2. &WriteToLog('STARTED');
  3. for(;;){
  4. foreach $host (@hosts) {
  5. $socket = IO::Socket::INET->new("$host:80");
  6. if (!$socket) {
  7. &WriteToLog("HOST DOWN: $host");
  8. exec("curl -u USERNAME:PASSWORD -d status=\"$host is DOWN\" http://twitter.com/statuses/update.json 1>/dev/null 2>/dev/null");
  9. }else{
  10. close($socket);
  11. }
  12. }
  13. sleep(60);
  14. }
  15. &WriteToLog('STOPPED');
  16. sub WriteToLog {
  17. my($msg) = @_;
  18. @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
  19. @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
  20. ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
  21. $year = 1900 + $yearOffset;
  22. $theTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year";
  23. open (MYFILE, '>> /etc/twitter/monitor.log');
  24. print MYFILE "$theTime $msg\n";
  25. close (MYFILE);
  26. }


Muy agradecido a los que salvar a mi cordura restantes.
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Abril 19th, 2009, 7:51 pm

Publicar Información

  • Total de mensajes en este tema: 1 mensaje
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 91 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC