-
Notifications
You must be signed in to change notification settings - Fork 0
/
ip.sh
executable file
·50 lines (42 loc) · 1.06 KB
/
ip.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
set -e
cd "$(dirname "$0")"
#####
#Save current and old IP
#####
#Settings
xdate="$(date "+[%Y-%m-%d %H:%M:%S]")"
#c=current
#if file doesn't exit create
cip_file="ip.txt"
if [ ! -e $cip_file ]; then
echo -e "IP file not found! \nCreate IP file"
echo "1.1.1.1" > $cip_file
fi
#got current ip adresse
#if file doesn't exit create
cip="$(curl --silent https://ifconfig.me/ip)"
#l=last
lip_file="/tmp/l_ip.txt"
if [ ! -e $lip_file ]; then
echo -e "Last IP file not found! \nCreate Last IP file";
echo "$cip" > $lip_file
fi
#o=old
#if file doesn't exit create
oip_file="/tmp/ip_old.txt"
if [ ! -e $oip_file ]; then
echo -e "Old IP file not found! \necho Create Last IP file"
echo "$xdate - " > $oip_file
fi
#check changes, if exist set new ip to last
if [ $cip = $(cat ip.txt) ]; then
echo -e "Current IP is equal to last, noting to do. \nBye!"
else
echo "IP Changed! $(cat ip.txt) -> $cip "
echo "Save last ip in $oip_file"
echo "$xdate $(cat ip.txt)" >> $oip_file
echo "Set current IP!"
echo "$cip" > $cip_file
echo "$cip" > $lip_file
fi