Skip to content

Instantly share code, notes, and snippets.

@iordic
Last active April 8, 2017 16:17
Show Gist options
  • Save iordic/c2dc415b46d704811456b8b39fb822fb to your computer and use it in GitHub Desktop.
Save iordic/c2dc415b46d704811456b8b39fb822fb to your computer and use it in GitHub Desktop.
Script de sh que registra la ip pública en un fichero de texto a modo de log
#! /bin/sh
# Script que registra la ip publica en un fichero de texto
# Usado en un router con OpenWrt
# Author: Jordi Castelló
wget http://checkip.dyndns.com/index.html -O iplog.tmp 2>/dev/null
cut -d' ' -f6 iplog.tmp > iplog-cache.tmp # Eliminamos las partes que no nos interesan
cut -d'<' -f1 iplog-cache.tmp > iplog.tmp
public_ip=$(cat iplog.tmp) # Guardamos en una variable el resultado
rm iplog.tmp iplog-cache.tmp # Eliminamos ficheros
if [ -e /mnt/datos/pubip.log ] ; then
echo `date +"(%Y/%m/%d-%H:%M:%S)"` - IP publica: $public_ip >> /mnt/datos/pubip.log
else
touch /mnt/datos/pubip.log
echo "###################################################" >> /mnt/datos/pubip.log
echo "# LISTAS DE ASIGNACIONES DE IP PUBLICAS #" >> /mnt/datos/pubip.log
echo "###################################################" >> /mnt/datos/pubip.log
echo "" >> /mnt/datos/pubip.log
echo `date +"(%Y/%m/%d-%H:%M:%S)"` - IP publica: $public_ip >> /mnt/datos/pubip.log
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment