+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 5 of 8

Thread: Ping script using Redhat and BAsh

  1. #1
    luongsonbac13
    Guest

    Ping script using Redhat and BAsh

    Alright, I have being checking out various posting here trying to hack together something for a friend



    Needed:



    A script that can run in cron doing:

    ping of several hosts and notifying via email when they are unavailable.



    I am not going to post my non working messes (I am a basic scripter), but I have tried several approaches and just dont have the strong knowledge base to push variables around in a script.



    Suggestions Please..



    using: bash on redhat linux box



    actually here is the latest script:

    #!/bin/bsh

    #################################

    for file in `cat iplist.txt`

    do

    ping -c 1 -A $file | grep errors | wc -l

    read tom

    echo $tom

    if [ "$tom" != 0 ]

    then

    mail -s"Test" exx@xx.com

    else

    mail -s"Worked" exx@xx.com

    fi

    done



    OH how the heck do I get the mail program to just fire out the email? I know in solaris mailx will nicely shoot out the email...



    Also my variations of this produce nice frustrating results...like the if then aint working right. Figure read is seen it as a string? At least that is my guess...
    More Information:
    1. add --ping option - decrease the ping time to 10 sec (use --ping above if you don't like it) - hack the init script to use the new --ping option
    2. 131 gemstone bash# ping starship bash# ping gemstone bash# telnet gemstone bash# ftp gemstone
    3. com and as soon as i can't ping it anymore, I want to restart my network card - this script
    4. bash script is downloaded from a server every time the user logs in, no one can exclude the possibility that it did something
    5. script: #!/bin/bash echo "Content-type: text/plain" echo /bin/ping -c1 www

    More:


  2. #2
    nguyenvietthang
    Guest


    Quote:







    Originally posted by edkung

    Needed:



    A script that can run in cron doing:

    ping of several hosts and notifying via email when they are unavailable.



    using: bash on redhat linux box



    actually here is the latest script:

    #!/bin/bsh

    #################################

    for file in `cat iplist.txt`

    do

    ping -c 1 -A $file | grep errors | wc -l

    read tom

    echo $tom

    if [ "$tom" != 0 ]

    then

    mail -s"Test" exx@xx.com

    else

    mail -s"Worked" exx@xx.com

    fi

    done



    For starters, make sure that iplist.txt is in the correct directory. I assume it will always be in the same directory as the script? If not, add a path to the file name. Second, for the mail portion, try using sendmail as this is commonly installed on RedHat. To check the status of the ping command, use a variable to capture the status. Not sure what the return value is of that ping command, adjust the IF statement to match.



    for file in `cat iplist.txt`

    do

    PING_TEST=0

    PING_TEST=`ping -c 1 -A $file | grep errors | wc -l`

    #read tom

    #echo $tom

    if [ $PING_TEST -ne 0 ]

    #Use -ne (not equal) for integer comparison

    then

    sendmail -s"Test" exx@xx.com

    else

    sendmail -s"Worked" exx@xx.com

    fi

    done
    More Information:
    1. BASH Scripting Introduction to BASH Command Line Interface (CLI) o Identify BASH installation & key configuration files on RedHat & Debian GNU/Linux distros
    2. idea that would help me is to have a bash script that will ping a few destinations every minute, then do a traceroute to these destinations, record the time and all that output in a file
    3. The exact recipe I wanted, in a four line bash script
    4. copy below script into a file and name it as hostping
    5. And HELL NO! our product is definitely not a lame conglomerate of Bash scripts gluing many pieces
    6. 13 posts - 4 authors - Last post: Apr 2Imagine a ping script and it outputs each response as it is returned rather than wait until all 4 pings are completed and dumping the whole lot to

  3. #3
    domino24111
    Guest

    Thanks, that worked much better. Getting both the positive and negative results I originally wanted. I have to work on the sendmail part (get the right switches).



    Now here is another question



    Lets say in my iplist.txt file I want to include a name for the ip address

    ex: 192.168.60.5,router1



    and I want to have the email subject to say



    Router1 is down!



    I am thinking that any of the text editors will help with this...(sed awk or what have you)
    More Information:
    1. bin/bash oct1=10 oct2=0 oct3=0 oct4=1 while [ $oct3 -lt 3 ] do while [ $oct4 -lt 255 ] do if [ -n "`ping -c1 $oct1
    2. zip - bash script designed to make it easy to synchronize your development site and your production site
    3. I just started out with bash scripting and decided to write a simple ping program that pings my network and record the
    4. Labels: awk, bash, grep, linux, monitoring, nmap, ping, script, security, shell, sysadmin, tips for loop
    5. using: bash on redhat linux box actually here is the latest script: #!/bin/bsh #################################
    6. My name is Steven and I was wondering if there is an easy way in a bash shell script to tell if the variable you read is numberic? For example
    7. Write a bash script which could be scheduled in cron to run nightly
    8. Bash device script to wait 1 second before attempting to determine device hostname
    9. If the ping is unsuccessful, the script runs the command (we'll substitute an actual

  4. #4
    duongqua
    Guest

    Using Oombera's suggestion on another thread....

    echo "1024MB" | awk '{print substr($1,0,4)}' # print first four numbers / chars

    echo "1024MB" | sed 's/[A-Za-z]*//g' # removes all letters

    x=${x%%[A-Za-z]*} # remove everything after (and including) any chars - Note this is specific to Korn Shell



    setup your variables in you iplist.txt so that they are in a consistent format. Then, instead of using $FILE, use one of the above suggestions to get either the IP address or the actual name. You will of course have to make some modifications. The code above will remove the characters from the variables. You will need to remove numbers and dots to reverse this.



    Do a google search on SendMail Flags to get correct formatting.
    More Information:
    1. RedHat has have provided a shell script which lists the affected packages and can verify that none of them are installed on a system:
    2. I have also tried running the script with out '[]' but executes the ping command
    3. Now that you have the ability to translate simple Bash scripts and functions into Python, let's get away from the nonsensical scripts and actually write something useful
    4. Tagged as: eq, for loop, grep command, hostname, linux, loop method, mail command, monitor host using ping script, ping command, ping request, shell loops, shell script, space hosts, unix, unix
    5. 3 posts - Last post: Oct 26, 2004I have compiled the following script to run a ping to a given IP address and print a timestamp every 20 lines
    6. The script to bind is: #!/bin/bash BRIF=br0 echo "Connecting interface $1 to bridge $BRIF" /
    7. We have seen how Python can implement system calls to run commands in sequence, just like a regular Bash script
    8. bin/bash for ((i=0;i<=10000;i++)); do ping x

  5. #5
    namdonganh
    Guest

    Or you could split the variable up right away and store both parts in separate variables:



    for file in `cat iplist.txt`

    do

    ipAdd=`echo $file | awk -F, '{print $1}'

    failMsg=`echo $file | awk -F, '{print $2}'

    PING_TEST=0

    PING_TEST=`ping -c 1 -A $ipAdd | grep errors | wc -l`

    #read tom

    #echo $tom

    if [ $PING_TEST -ne 0 ]

    #Use -ne (not equal) for integer comparison

    then

    sendmail -s"$failMsg is down!" exx@xx.com

    else

    sendmail -s"Worked" exx@xx.com

    fi

    done
    More Information:
    1. This is a very simple script that simply displays a dialog and asks the user which host he would like to ping, then displays the result in a tailbox dialog
    2. It could be used in your scripting not inside a loop, but specifying the range of ips to ping, in just one command
    3. On a Linux server I'm atempting to build a script which pings multiple devices
    4. If that's the case, don't hire another employee; let this simple Linux bash script do the monitoring for you
    5. Redhat bash, here's my code (ignore my poor coding, I'm a newbie and need to
    6. The script looks simple and nice… but how to do run it on redhat? do I just put on specific folder? Cron job? please let me know
    7. UNIX / Linux Shell Script For Monitoring System network with ping command · Shell Script To Build and Install vnstat Network Traffic Monitor
    8. You can modify script as follows: #!/bin/bash ADMIN="me@somewher
    9. say, cable modem, etc… write a script that determines the status of your ping and to simply reconnect it if needed
    10. I wrote a little script a very simple one that given a list of hosts and IP addresses will ping a host and if it is detected as down it will

+ Reply to Thread
Page 1 of 2
1 2 LastLast

Similar Threads

  1. strange BASH script behavior
    I took a class on using linux a little while ago which included bash scripting, but I haven't done any scripting since then. Today I decided it would...
  2. Looking for bash.org clone script.
    Or if anyone thinks they can build it for me, I'd be interested. Keep in mind im extremely low on the budget side. Basically I just need a script...
  3. Bash script: Online-Announcement on bash script.
    Hello, This code will provide online-announcement on your bash/script. Code: NEWSURL=" if wget -q $NEWSURL; then echo "News Content:"...
  4. Help with Bash Script
    Hi all, I'd like to write a bash script to help me manage photo files on our webserver. The website is for a real estate company that gets...
  5. BASH shell script question
    I want to make shell script that takes a list of host names on my network as command line arguments and displays whether the hosts are up or down,...

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
Automatic Translations (Powered by Powered by Google):
Afrikaans Albanian Arabic Belarusian Bulgarian Catalan Chinese Croatian Czech Danish Dutch English Estonian Filipino Finnish French Galician German Greek Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Taiwanese Thai Turkish Ukrainian Vietnamese Welsh Yiddish