Script para Enviar IP vía Mail

Autor: @Desconocido
Descripción: Este script comprueba la dirección IP pública de un PC y la envia a una dirección de correo.
Es útil si tiene el PC con una conexión a internet sin IP fija y se quiere conectar a él remotamente.
Puede ejecutarlo directamente con: ./ o añadir la siguiente linea en un script de inicio: nohup &>/dev/null & Para ejecutarlo, primero debe modificar las variables del principio del script con sus datos de correo.


# Script designed to read your public IP address from
# at intervals and notify any changes by sending an email for you.

# wget and sendEmail with tsl support must be installed on your system.

# Usage:  (if it can be found in your session environment PATH)
# or if you want to run it on the background:  nohup &>/dev/null &

# Please, you must modify the next variables to suit your needs:  # An account to send the email with the ip.
RECEIVE=$DELIVER  # An account to get the email. Don't modify to send it to the same address you especified above.  # The smtp server's port of the emailer account. Example:
TLS=yes  # yes|no    Does the mail server accept/require TLS or SSL encryption?

# The script starts here.

PATH=$PATH:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin  # paranoia
wget -q -t 4 --no-proxy --no-cache --no-cookies -o /dev/null -O /var/publicip
if [ $? -ne 0 ] ; then sleep 5m ; READ_IP ; fi
sendEmail -q -f $DELIVER -t $RECEIVE -u $SUBJECT -m $MESSAGE -s $SMTP_SERVER -xu $MAIL_USER -xp $MAIL_PASS -o tls=$TLS
if [ $? -ne 0 ] ; then sleep 5m ; SEND_IP ; fi

if [ $DELIVER == ]
then echo ; echo "  Warning!  You must carefully edit some variables of the script first of all." ; echo
  if [ ! -e /var/publicip-sent ]
  then echo 0 > /var/publicip-sent
  while true
  do READ_IP ; sleep 12s ; sync  # paranoia
    if [ `cat /var/publicip` != `cat /var/publicip-sent` ]
    SUBJECT=`hostname ; echo "IP changed:" ; cat /var/publicip`
    MESSAGE=`cat /var/publicip ; echo ; date +%F\ %T`
    SEND_IP && mv /var/publicip /var/publicip-sent
    else rm /var/publicip
  sleep 60m

# That was all.

# Perhaps you didn't like having to type your email password directly in the script,
# a workaround could be to assign a value like MAIL_PASS=`cat ~/password.txt` , then
# write a file called ~/password.txt with only the password in it and run the script.
# Don't forget that the password plain text file should only be readable by you,
# modificate it's permissions with chmod if needed.

2 comentarios:

Demian Freeak dijo...

Hola, muy buen blog! revisa la linea 44 demaciados argumentos
./ line 44: [: too many arguments

Arturo Fernandez dijo...

Buen día, a mi me da el mismo error en la línea 44, al revisar paso a paso el script lo que ocurre es que no genera el fichero publicip