Find the answer to your Linux question:
Results 1 to 7 of 7
I am having trouble with a small script that I can't get it to do right. I am very new to Linux and can use some help. What I am ...
  1. #1
    Just Joined!
    Join Date
    Sep 2008
    Location
    Bowling Green, KY
    Posts
    6

    Scripting Help

    I am having trouble with a small script that I can't get it to do right. I am very new to Linux and can use some help. What I am trying to do is ping on a private network the other Linux machines to see if they are on-line. Two things I can use help on first the script will not show me which machine is responding slow and second the out come does not give me what I want to see. First the script.

    pingtest() {
    ping=`ping -c2 $1 | tail -2`
    loss=`echo $ping | cut -d"," -f3 | cut -d" " -f2`
    delay=`echo $ping | cut -d"=" -f2 | cut -d"." -f1`
    if [ "$loss" = "100%" ] ; then
    echo `date` $1 No Route to Host!!!!!!!! >>e.log
    echo $1 No Route to Host!!!!!!!!!
    elif [ "$loss" != "0%" ] ; then
    echo $1 Not responding at all !!!!!!!!!!
    echo `date` $1 Not responding at all >>e.log
    else
    if [ "$delay" -lt 10 ] ; then
    echo $1 is responding normally
    # echo `date` $1 is responding normally >>e.log
    else
    echo $1 is responding slow
    fi
    fi
    }

    Now the out come.

    At the first ESP echo the line is messed up. What have I missed?

    report
    logins IP Adderss

    sixa 132.147.160.62 cat62 is responding normally
    fivea 132.147.160.52 cat52 is responding normally
    fiveb 132.147.160.53 cat53 is responding normally
    fivec 132.147.160.54 cat54 is responding normally
    foura 132.147.160.42 cat42 Not responding at all !!!!!!!!!!
    fourb 132.147.160.43 cat43 is responding normally
    fourc 132.147.160.44 cat44 is responding normally
    threea 132.147.160.32 cat32 is responding normally
    threeb 132.147.160.33 cat33 is responding normally
    threec 132.147.160.34 cat34 is responding normally
    twoa 132.147.160.22 cat22 is responding normally
    twob 132.147.160.23 cat23 is responding normally
    l&d 132.147.160.24 cat24 Not responding at all !!!!!!!!!!
    xray 132.147.160.12 cat12 is responding normally
    pacu 132.147.160.65 cat65 is responding normally
    miner 132.147.160.64 cat64 is responding normally
    asgy 132.147.160.66 cat66 is responding normally
    dsvr 132.147.160.55 cat55 is responding normally
    or 132.147.160.18 cat18 is responding normally
    er 132.147.160.11 cat11 is responding normally
    spare 132.147.160.63 cat63 is responding normally
    spare 132.147.160.67 cat67 is responding normally
    spare 132.147.160.72 cat72 is responding normally
    cath 132.147.160.71 cat71 Not responding at all !!!!!!!!!!
    ###############ESP##############esp1 132.147.160.80 esp1 is respondi
    ng normally
    esp2 132.147.160.81 esp2 is responding normally
    esp3 132.147.160.82 esp3 is responding normally
    esp4 132.147.160.83 esp4 is responding normally
    esp5 132.147.160.84 esp5 is responding normally
    esp6 132.147.160.85 esp6 is responding normally
    esp7 132.147.160.86 esp7 is responding normally
    esp8 132.147.160.87 esp8 is responding normally
    esp9 132.147.160.88 esp9 is responding normally
    esp10 132.147.160.89 esp10 is responding normally
    esp11 132.147.160.90 esp11 is responding normally
    esp12 132.147.160.91 esp12 is responding normally
    esp13 132.147.160.92 esp13 is responding normally
    esp14 132.147.160.93 esp14 is responding normally
    esp15 132.147.160.94 esp15 is responding normally
    esp16 132.147.160.95 esp16 is responding normally
    esp19 132.147.160.103 esp19 is responding normally

  2. #2
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    Welcome Newperson!

    This script is part of a larger script, or maybe it gets input from another file??

    Because it misses a newline character somewhere that is not showing in your example. I think.
    Can't tell an OS by it's GUI

  3. #3
    Just Joined!
    Join Date
    Sep 2008
    Location
    Bowling Green, KY
    Posts
    6
    I see what you are saying. I will post the intire script and if you would look at it. I still cannot see the missing newline you spoke of. OH and thanks a million for you help.

    pingtest() {
    ping=`ping -c2 $1 | tail -2`
    loss=`echo $ping | cut -d"," -f3 | cut -d" " -f2`
    delay=`echo $ping | cut -d"=" -f2 | cut -d"." -f1`
    if [ "$loss" = "100%" ] ; then
    echo `date` $1 No Route to Host!!!!!!!! >>e.log
    echo $1 No Route to Host!!!!!!!!!
    elif [ "$loss" != "0%" ] ; then
    echo $1 Not responding at all !!!!!!!!!!
    echo `date` $1 Not responding at all >>e.log
    else
    if [ "$delay" -lt 10 ] ; then
    echo $1 is responding normally
    # echo `date` $1 is responding normally >>e.log
    else
    echo $1 is responding slow
    fi
    fi
    }
    echo -n "logins IP Adderss"
    echo
    echo
    echo -n "sixa 132.147.160.62 ";pingtest cat62
    echo -n "fivea 132.147.160.52 ";pingtest cat52
    echo -n "fiveb 132.147.160.53 ";pingtest cat53
    echo -n "fivec 132.147.160.54 ";pingtest cat54
    echo -n "foura 132.147.160.42 ";pingtest cat42
    echo -n "fourb 132.147.160.43 ";pingtest cat43
    echo -n "fourc 132.147.160.44 ";pingtest cat44
    echo -n "threea 132.147.160.32 ";pingtest cat32
    echo -n "threeb 132.147.160.33 ";pingtest cat33
    echo -n "threec 132.147.160.34 ";pingtest cat34
    echo -n "twoa 132.147.160.22 ";pingtest cat22
    echo -n "twob 132.147.160.23 ";pingtest cat23
    echo -n "l&d 132.147.160.24 ";pingtest cat24
    echo -n "xray 132.147.160.12 ";pingtest cat12
    echo -n "pacu 132.147.160.65 ";pingtest cat65
    echo -n "miner 132.147.160.64 ";pingtest cat64
    echo -n "asgy 132.147.160.66 ";pingtest cat66
    echo -n "dsvr 132.147.160.55 ";pingtest cat55
    echo -n "or 132.147.160.18 ";pingtest cat18
    echo -n "er 132.147.160.11 ";pingtest cat11
    echo -n "spare 132.147.160.63 ";pingtest cat63
    echo -n "spare 132.147.160.67 ";pingtest cat67
    echo -n "spare 132.147.160.72 ";pingtest cat72
    echo -n "cath 132.147.160.71 ";pingtest cat71
    echo -n
    echo -n
    echo -n "###############ESP##############"
    echo -n "esp1 132.147.160.80 ";pingtest esp1
    echo -n "esp2 132.147.160.81 ";pingtest esp2
    echo -n "esp3 132.147.160.82 ";pingtest esp3
    echo -n "esp4 132.147.160.83 ";pingtest esp4
    echo -n "esp5 132.147.160.84 ";pingtest esp5
    echo -n "esp6 132.147.160.85 ";pingtest esp6
    echo -n "esp7 132.147.160.86 ";pingtest esp7
    echo -n "esp8 132.147.160.87 ";pingtest esp8
    echo -n "esp9 132.147.160.88 ";pingtest esp9
    echo -n "esp10 132.147.160.89 ";pingtest esp10
    echo -n "esp11 132.147.160.90 ";pingtest esp11
    echo -n "esp12 132.147.160.91 ";pingtest esp12
    echo -n "esp13 132.147.160.92 ";pingtest esp13
    echo -n "esp14 132.147.160.93 ";pingtest esp14
    echo -n "esp15 132.147.160.94 ";pingtest esp15
    echo -n "esp16 132.147.160.95 ";pingtest esp16
    #echo -n "esp17 132.147.160.97 ";pingtest esp17
    #echo -n "esp18 132.147.160.96 ";pingtest esp18
    echo -n "esp19 132.147.160.103 ";pingtest esp19
    #echo -n "online cats ";online_gui_cats

  4. #4
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    Quote Originally Posted by Newperson
    I still cannot see the missing newline you spoke of.
    Oh, but I do

    It's this:
    echo -n
    echo -n
    echo -n "###############ESP##############"

    From the man:
    Echo the STRING(s) to standard output.

    -n do not output the trailing newline
    I can see why you put them in the other lines, because it makes sense to suppress the newline character there. But not in the blank lines disappearing and the dividing line "###############ESP##############"
    Remove the -n from those and you're done



    EDIT:
    You could also have done:
    Code:
    cat << EOF
           <snip>
           spare 132.147.160.67 `pingtest cat67`
           spare 132.147.160.72 `pingtest cat72`
           cath 132.147.160.71  `pingtest cat71`
    
    
           ###############ESP##############
           esp1 132.147.160.80  `pingtest esp1`
           esp2 132.147.160.81  `pingtest esp2`
           esp3 132.147.160.82  `pingtest esp3`
           <snip>
    EOF
    Can't tell an OS by it's GUI

  5. #5
    Just Joined!
    Join Date
    Sep 2008
    Location
    Bowling Green, KY
    Posts
    6
    You were 100&#37; correct on the -n I removed them and works fine. Funny how a little thing like that can make me scratch my head for two days. Now to the second part how can I tell which cat is responding slow on the network. The reason why I need to know is because some of the pc's here are problem areas and if it is a network problem I will remove the pc and replace it or check out the fiber and hub going to them. Once again thanks.

  6. #6
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    Quote Originally Posted by Newperson
    Funny how a little thing like that can make me scratch my head for two days.
    It's always the little things

    Quote Originally Posted by Newperson
    Now to the second part how can I tell which cat is responding slow on the network.
    Measuring response to a ping request is a crude measurement. So an individual measurement is very unreliable.


    There are of course tools available that help keep an eye on your network performance. Nagios is one that comes to mind.
    Can't tell an OS by it's GUI

  7. #7
    Just Joined!
    Join Date
    Sep 2008
    Location
    Bowling Green, KY
    Posts
    6
    Thank you for the reply. The network I admimistartor is on it's own network and is not and cannot be connected to the internet. The system is considered to be a life safty equipment for patients. There for I am bound to what is there software speaking. However I like the looks of Nagios and will consider installing it on my own network. Once agian thank you for solving my problem. Looks like I found the right forum.

Posting Permissions

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