#!/usr/bin/perl # # Enviamos un correo electrónico a $TO con la sentencia sql que debe ejecutar # para actualizar la entrada dns correspondiente a $USER # # DEBEMOS MODIFICAR EL CAMPO $USER ANTES DE USAR EL SCRIPT use MIME::Lite; use Net::SMTP; # Variables $USER="usuario"; $TO="administrador\@gadelek.com"; # void main() # Check if we have internet connection. Exit if we don't # if >0 , then no ping response. If 0, ping ok if (system "ping -c 1 google.com > /dev/null"){ $connection="no"; print "No internet connection\n"; exit; } $FROM="dynamicdns\@$USER.local.gadelek.com"; $cmd= 'links -source www.cualesmiip.com |grep -i "tu ip real" |awk \'{print $5}\' |cut -d">" -f 2'; system "$cmd > /tmp/mydynamicip"; open(DATA, "/tmp/mydynamicip"); @raw_data=; close(DATA); unlink("/tmp/mydynamicip"); foreach $LINE (@raw_data) { chomp($LINE); $MYIP=$LINE; } $MESSAGE="update direcciones set direccion=\"$MYIP\" where nombre=\"$USER\""; # Send the mail MIME::Lite->send('smtp', "gadelek.com", Timeout=>60); $msg = MIME::Lite->new( From =>$FROM, To =>$TO, Subject =>'dynamic ip update', Type =>'text', Data => $MESSAGE, ); ### Now this will do the right thing: $msg->send; ### will now use Net::SMTP as shown above