#!/bin/bash get_old_ip(){ if [ -f "${1}"ip.txt ]; then OLD_IP=$(cat "${1}"ip.txt 2>/dev/null) if [ -z "${OLD_IP}" ]; then return 1 else return 0 fi else return 1 fi } get_cur_ip(){ CUR_IP=$(curl ifconfig.me 2>/dev/null) if [ -z "${CUR_IP}" ]; then return 1 else return 0 fi } get_old_ip "${1}" && { get_cur_ip "${1}" && { [ "${OLD_IP}" == "${CUR_IP}" ] && { echo -n "${CUR_IP}" > "${1}"ip.txt echo -n "${CUR_IP}" exit 0 }\ || { echo -n "${CUR_IP}" > "${1}"ip.txt echo -n "${CUR_IP}" exit 0 } } }\ || get_cur_ip "${1}" && { echo -n "${CUR_IP}" > "${1}"ip.txt echo -n "${CUR_IP}" exit 0 } exit "${?}"