welshmike
May 19th, 2013, 01:00 PM
My apologies as this is not strictly a Ubuntu question.
My connection to my ISP, TalkTalk, disconnects for a minute or two several times a day.
So I've written a crude bash script shown below to keep a log of my public IP address.
I also show the contents of the log produced over a few seconds.
I'd really like to get the IP address on the same line as the date and time.
How may I do this in my script please?
My crude bash script
#!/bin/bash
# wanstatus: Monitor WideAreaNetwork status for disconnections
# After testing make this script a startup application
# sleep 5 minutes (300 seconds)to be sure internet connection is established
#sleep 300
cd /home/mike/Documents
# set start name of wanstatus log (in Documents folder)
logfile="logfile"
logfile=wanstatuslog-$(date +%Y%m%d)-$(date +%H%M%S)
echo "Wide Area Network status log to record disconnections by change of IP address." >> $logfile
echo "================================================== ============================" >> $logfile
# start loop here?
while [ 1 = 1 ]
do
# sleep 1 minute (60 seconds) before obtaining IP address again
#sleep 60
sleep 1 # just sleep 1 second for test purposes
# assign dated value to variable logtime and put my public IP address alongside the time in the logfile
lineout="Date and Time: "
logtime=$(date +%Y%m%d)-$(date +%H%M%S) # date and time
ip=" IP address: "
lineout="$lineout $logtime $ip"
echo $lineout >> $logfile
curl ifconfig.me >> ipaddress
cat ipaddress >> $logfile
rm ipaddress
done
#next to do
# ? How do find out when IP address changes after an internet disconnect/reconnect ?
exit
The log file content for the first 4 iterations of the script loop
Wide Area Network status log to record disconnections by change of IP address.
================================================== ============================
Date and Time: 20130519-123308 IP address:
92.18.33.206
Date and Time: 20130519-123313 IP address:
92.18.33.206
Date and Time: 20130519-123317 IP address:
92.18.33.206
Date and Time: 20130519-123320 IP address:
92.18.33.206
My connection to my ISP, TalkTalk, disconnects for a minute or two several times a day.
So I've written a crude bash script shown below to keep a log of my public IP address.
I also show the contents of the log produced over a few seconds.
I'd really like to get the IP address on the same line as the date and time.
How may I do this in my script please?
My crude bash script
#!/bin/bash
# wanstatus: Monitor WideAreaNetwork status for disconnections
# After testing make this script a startup application
# sleep 5 minutes (300 seconds)to be sure internet connection is established
#sleep 300
cd /home/mike/Documents
# set start name of wanstatus log (in Documents folder)
logfile="logfile"
logfile=wanstatuslog-$(date +%Y%m%d)-$(date +%H%M%S)
echo "Wide Area Network status log to record disconnections by change of IP address." >> $logfile
echo "================================================== ============================" >> $logfile
# start loop here?
while [ 1 = 1 ]
do
# sleep 1 minute (60 seconds) before obtaining IP address again
#sleep 60
sleep 1 # just sleep 1 second for test purposes
# assign dated value to variable logtime and put my public IP address alongside the time in the logfile
lineout="Date and Time: "
logtime=$(date +%Y%m%d)-$(date +%H%M%S) # date and time
ip=" IP address: "
lineout="$lineout $logtime $ip"
echo $lineout >> $logfile
curl ifconfig.me >> ipaddress
cat ipaddress >> $logfile
rm ipaddress
done
#next to do
# ? How do find out when IP address changes after an internet disconnect/reconnect ?
exit
The log file content for the first 4 iterations of the script loop
Wide Area Network status log to record disconnections by change of IP address.
================================================== ============================
Date and Time: 20130519-123308 IP address:
92.18.33.206
Date and Time: 20130519-123313 IP address:
92.18.33.206
Date and Time: 20130519-123317 IP address:
92.18.33.206
Date and Time: 20130519-123320 IP address:
92.18.33.206