Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
help me with scripts to check link activity
Results 1 to 7 of 7

Thread: help me with scripts to check link activity

  1. #1
    Moderator
    Good Guru
    Compunuts's Avatar
    Join Date
    May 2001
    Location
    California
    Posts
    3,935

    help me with scripts to check link activity

    My Comcarp link is in terrible shape lately even after what they say was a major upgrade. The problem is the link will go down multiple times a day and my gateway box can't connect to modem. I need to manually ifdown/ifup it.

    So if some of you guys could help me writing a script, that would be great (since I know nothing about scripting).

    1/ What I want is the script to do "ping" to well known address such as google.com . If it receive replies, then assume the link is active and do nothing.

    2/ If it doesn't get link active replies, such as with no TTL, then do the following.

    a/ ifdown etho
    b/ ifup etho

    3/ Then it will do re-check such as restart the script or put it in loop so that it will execute at least one more time to make sure the link is up.

    Is it possible? Some of you guys knows any program that can do what I wanted?

    TIA

  2. #2
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811

    Re:help me with scripts to check link activity

    something like this:
    Code:
    #!/bin/sh
    
    if ! [ -x /sbin/ifdown ]; then
        exit 0
    fi
    if ! [ -x /sbin/ifup ]; then
        exit 0
    fi
    if ! [ -x /bin/ping ]; then
        exit 0
    fi
    
    /bin/ping -c1 google.com >/dev/null 2>&1
    while [ $? -ge 1 ]; do
        /sbin/ifdown eth0 >/dev/null 2>&1
        /sbin/ifup eth0 >/dev/null 2>&1
        sleep 3
        /bin/ping -c1 google.com >/dev/null 2>&1
    done

  3. #3
    Moderator
    Good Guru
    Compunuts's Avatar
    Join Date
    May 2001
    Location
    California
    Posts
    3,935

    Re:help me with scripts to check link activity

    Will your script do "ping" first?

  4. #4
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811

    Re:help me with scripts to check link activity

    Eksplanation:
    Code:
    /bin/ping -c1 google.com >/dev/null 2>&1
    Ping host to see if it's up
    Code:
    while [ $? -ge 1 ]; do
    while return value is 1 or grater, return value of a success here is 0, any failuer will result in 1(internal error in ping command) 2(unknown host, usualy no link) 3(no route to host), can't remember if theres more
    Code:
        /sbin/ifdown eth0 >/dev/null 2>&1
        /sbin/ifup eth0 >/dev/null 2>&1
        sleep 3
    bring interface down, set it up again and wayt a few seconds be for initiating that crusial
    Code:
    /bin/ping -c1 google.com >/dev/null 2>&1
    to ping host and have the return value once more holding that condition value the while loop is controled by.
    The -c1 is to tell ping to only send one package, so if for some reason where the link is up it dost return, it will reload the network, but thats a question on patience for script runtime and failproof issue.

    It can easily be altered to like run this once every 5 minuts or so, just embrace the initial ping and the while loop in a while loop which does nothing more than run forever and sleep any time you like, something like:
    Code:
    #!/bin/sh
    
    if ! [ -x /sbin/ifdown ]; then
        exit 0
    fi
    if ! [ -x /sbin/ifup ]; then
        exit 0
    fi
    if ! [ -x /bin/ping ]; then
        exit 0
    fi
    
    while [ 2 -le 3 ]; do
        /bin/ping -c1 google.com >/dev/null 2>&1
        while [ $? -ge 1 ]; do
            /sbin/ifdown eth0 >/dev/null 2>&1
            /sbin/ifup eth0 >/dev/null 2>&1
            sleep 3
            /bin/ping -c1 google.com >/dev/null 2>&1
        done
        sleep 300
    done
    This will run for ever and test the connection every 5 minuts.

    Sorry that I havn't been around much in tha last 2 years or so.. Yet I've been around just didn't participated in any answering questions here.. Since I didn't find that much of interrest, altho this specific question caught my attention.

  5. #5
    Moderator
    Good Guru
    Compunuts's Avatar
    Join Date
    May 2001
    Location
    California
    Posts
    3,935

    Re:help me with scripts to check link activity

    Dude, thank you thank you.

    I will try it out. I was thinking to run the script via crontab to wake up and run every hour or so. I don't really need every 5 minutes. So just curious, is it resource intensive to run the script once and let it restart its own with sleep codes than running with crontab for example? Just curious. I'm a noob at coding.

  6. #6
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811

    Re:help me with scripts to check link activity

    the most effecient way, is to run it from crontab, else you'll have a sleep process which isn't exactly using any system resources, but none the less is taking up time in the round robin schedular for the other running processes.
    This is however only of disturbance on a system that is running close to it's maximum capacity, but why invent the wheel once more, when you already have crontab running to schedule revoking of a process.

  7. #7
    Moderator
    Good Guru
    Compunuts's Avatar
    Join Date
    May 2001
    Location
    California
    Posts
    3,935

    Re:help me with scripts to check link activity

    [quote author=redhead link=board=9;threadid=10336;start=0#msg93120 date=1112571781]
    but why invent the wheel once more, when you already have crontab running to schedule revoking of a process.
    [/quote]Yes, I was thinking the same thing. Thanks.

Similar Threads

  1. Frustration setting cards to eth(n) names.. major system slowdown, odd activity
    By trycatch in forum Linux - Hardware, Networking & Security
    Replies: 2
    Last Post: 04-30-2010, 03:25 PM
  2. Activity
    By RickDev in forum Announcements and Suggestions
    Replies: 4
    Last Post: 08-16-2005, 08:23 AM
  3. Scripts
    By countach44 in forum Windows - General Topics
    Replies: 8
    Last Post: 05-25-2005, 10:47 PM
  4. Can this be done with Scripts ??
    By Compunuts in forum Programming
    Replies: 14
    Last Post: 11-08-2002, 08:06 AM
  5. culmintating activity
    By agar in forum General Chat
    Replies: 16
    Last Post: 02-15-2002, 09:34 PM

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
  •