Results 1 to 5 of 5

Thread: Monitoring WideAreaNetwork status for disconnections

  1. #1
    Join Date
    Apr 2008
    Location
    Winchester, UK
    Beans
    277
    Distro
    Ubuntu 18.04 Bionic Beaver

    Monitoring WideAreaNetwork status for disconnections

    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
    ASUS ZenBook UX305 (Intel® Core™ M-5Y10c ) CPU @ 0.80GHz × 4, 8GiB RAM, 128GiB SSD, Ubuntu 18.04
    MSi CR620 (Novatech i3 Core i3-350M) 2.27GHz 2GiB RAM, 250GiB SSD, Ubuntu 18.04 & W10

  2. #2
    Join Date
    Apr 2008
    Location
    LOCATION=/dev/random
    Beans
    5,767
    Distro
    Ubuntu Development Release

    Re: Monitoring WideAreaNetwork status for disconnections

    I just use the following line in my root crontab to monitor my external IP...
    Code:
    0 * * * * echo "`date`  `curl -s ifconfig.me`" >> /var/log/externalip
    This gives me a log which looks like this...
    Code:
    ...
    Sun May 19 13:00:00 BST 2013  86.139.169.158
    Sun May 19 14:00:00 BST 2013  86.139.169.158
    Sun May 19 15:00:00 BST 2013  86.139.169.158
    I've got mine set to log every hour but you can easily change this by altering the timing in your crontab.
    Cheesemill

  3. #3
    Join Date
    Apr 2008
    Location
    Winchester, UK
    Beans
    277
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Monitoring WideAreaNetwork status for disconnections

    Many thanks for your solution in one line.

    As an old year 1964 mainframe Assembler programmer I need to get up to speed with Linux magic.
    ASUS ZenBook UX305 (Intel® Core™ M-5Y10c ) CPU @ 0.80GHz × 4, 8GiB RAM, 128GiB SSD, Ubuntu 18.04
    MSi CR620 (Novatech i3 Core i3-350M) 2.27GHz 2GiB RAM, 250GiB SSD, Ubuntu 18.04 & W10

  4. #4
    Join Date
    Aug 2005
    Beans
    6,024

    Re: Monitoring WideAreaNetwork status for disconnections

    Quote Originally Posted by welshmike View Post
    As an old year 1964 mainframe Assembler programmer I need to get up to speed with Linux magic.
    That makes you a real programmer in my book

    Love assembler.

  5. #5
    Join Date
    Apr 2008
    Location
    Winchester, UK
    Beans
    277
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Monitoring WideAreaNetwork status for disconnections

    Quote Originally Posted by mips View Post
    That makes you a real programmer in my book

    Love assembler.
    Before 360 Assembler it was 1400 Autocoder and SPS
    Earlier on I started with the mystery of programming a Ferranti Pegasus 1 with its nickel delay lines primary storage (RAM).
    ASUS ZenBook UX305 (Intel® Core™ M-5Y10c ) CPU @ 0.80GHz × 4, 8GiB RAM, 128GiB SSD, Ubuntu 18.04
    MSi CR620 (Novatech i3 Core i3-350M) 2.27GHz 2GiB RAM, 250GiB SSD, Ubuntu 18.04 & W10

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •