script for continous ping

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat script for continous ping
# 8  
Old 04-20-2012
If you saved this in a file myscript, can you run it as:-
Code:
ksh -x myscript

... and paste the output back.


Thanks, in advance,
Robin
# 9  
Old 04-20-2012
Now its showing. Not sure why ?

Code:
# ksh -x ping_out.sh
+ read in p t out rest
+ grep 'packets transmitted' /tmp/2012_04_20
+ [ 60 -ne 60 ]
+ echo 'All okay'
All okay

Moderator's Comments:
Mod Comment How to use code tags

Last edited by Scrutinizer; 04-20-2012 at 12:41 PM..
# 10  
Old 04-20-2012
Well, that looks good to me. In the "We have a problem" section, you would be best to put some reasons in using the values $in and $out so you can see what's happening, such as:-
Code:
...
...
if [ $in -ne $out ]
then
   echo "We have a problem.  I sent $in, but received $out."
else
...
...

The if statement
Code:
if [ $in -ne $out ]

is a numeric comparison. The operator -ne is "Not Numerically Equal" but causes trouble if you try to use it with alphanumerics on many systems. So, if the packets sent in are not equal to the packets got out, then you get the warning message. That's the logic.



Robin
Liverpool/Blackburn
UK
# 11  
Old 04-20-2012
Morning.

Not sure what OS or shell you're running, but this may help:

Code:
while :;do date >> /tmp/monitor.log;ping -c1 <server> | awk '/packets/{if($4 ~ 0) print $0)' >> /tmp/monitor.log;echo >> /tmp/monitor.log;done

Output to log:
Fri Apr 20 11:56:36 EDT 2012
1 packets transmitted, 0 received, 100% packet loss, time 0ms

This one-liner will dump the current date and time to a log file, send a single ping to the server in question, and use awk to only print when there is no response to the ping. You can open another shell and tail -f the log file to watch it in real-time.

Hope this helps.
# 12  
Old 04-20-2012
Thanks in2nix4life, i will try that. Thats a redhat linux machine.
2.6.18-308.1.1.el5, bash shell

Also thanks to rbatte1, but wondering why only ksh running it properly?
# 13  
Old 04-25-2012
Hi in2nix4life,
When running your script i am getting syntax errors.

Code:
awk: /packets/{if($4 ~ 0) print $0)
awk:                              ^ syntax error
awk: /packets/{if($4 ~ 0) print $0)
awk:                              ^ syntax error
awk: /packets/{if($4 ~ 0) print $0)
awk:                              ^ syntax error

Moderator's Comments:
Mod Comment Code tags for code please.
# 14  
Old 04-25-2012
That last ) ought to be a }.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

Ping test sends mail when ping fails

help with bash script! im am working on this script to make sure my server will stay online, so i made this script.. HOSTS="192.168.138.155" COUNT=4 pingtest(){ for myhost in "$@" do ping -c "$COUNT" "$myhost" &&return 1 done return 0 } if pingtest $HOSTS #100% failed... (4 Replies)
Discussion started by: mort3924
4 Replies

2. Shell Programming and Scripting

Extract & Manipulate continous data stream-- tcpdump

Hello; I have this rather tricky problem to solve --(to me, anyways) .. I am processing the following one liner with tcpdump.. tcpdump -i T3501 -A ether host 00:1e:49:29:fc:c9 or ether host 00:1b:2b:86:ec:1b or ether host 00:21:1c:98:a4:08 and net 149.83.6.0/24 | grep --line-buffered -B... (5 Replies)
Discussion started by: delphys
5 Replies

3. UNIX for Dummies Questions & Answers

help with continous scroll

I figured out my question. mods please delete. Thank you (2 Replies)
Discussion started by: rpmischris
2 Replies

4. Shell Programming and Scripting

Need bash script to ping the servers and rename the output file each time the script is ran

HI, I have a file serverlist in that all host names are placed. i have written a small script #./testping #! /bin/bash for i in `cat serverlist` do ping $i >> output.txt done so now it creates a file output.txt till here fine.. now each time i run this script the output file... (4 Replies)
Discussion started by: madhudeva
4 Replies

5. Shell Programming and Scripting

Awk Print Only Continous Numbers

Hi, i need help to print only those numbers which occur next to each other from a file. Input: 1 2 3 9 44 45 46 77 79 80 81 Desired Output: (8 Replies)
Discussion started by: saint2006
8 Replies

6. UNIX for Dummies Questions & Answers

To run a job continous (24x7)

Hi All, I have a job. I need to create a shell script which will execute that job continously i.e 24x7. Please help me in writing this script. Thanks, Kumar66 (6 Replies)
Discussion started by: kumar66
6 Replies

7. UNIX for Advanced & Expert Users

Continous Integration for Unix / Linux

Hi all, We have serious problem with continuous integration system for application building on few different platforms. (aix 5.2, 5.3 solaris 8,9 , SUSE Linux 9.3, 10 , Slackware Linux 10,11,12, RedHAt Enterprise Linux и Windows 2003) We need application ( program ) to do the following tasks:... (1 Reply)
Discussion started by: +Yan
1 Replies

8. UNIX for Dummies Questions & Answers

To remove Continous blank spaces from a file in UNIX

All... I want to remove blank spaces in file . I just leraned that we can use " cat <Input filename> | tr -s ‘ ‘ > <Target file name> " i also know with SED we can replace a blank space by other character by sed s/ /*/g filename. Please let me know how can i do that by... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies
Login or Register to Ask a Question