1826219 Members
2983 Online
109691 Solutions
New Discussion

Set a ping program

 
hangyu
Regular Advisor

Set a ping program

I would like to add a ping program that ping from host A to host B , the ping schedule is from 09:00am to 05:00pm daily , and periodically send a current time to the ping log ( so that I can easily to trace the time ) , can provide a simple script for me ?
what I do now is :
schedule job 1 : submit a ping job at 09:00am daily and kill it at 05:00pm
schedule job 2 : set a schedule job to run hourly "date >> ping.log"
2 REPLIES 2
Yogeeraj_1
Honored Contributor

Re: Set a ping program

hi,

since by default, ping waits for 1 sec between the sending of each packet, this can be easily implemented.

#!/bin/sh
export PINGLOG=/home/yd/logfiles/ping-$(date +%a)
cat /dev/null > $PINGLOG
i=1
while [ $i -le 8 ]
do
ping hostb -c 3600 >> $PINGLOG
date >> $PINGLOG
i=`expr $i + 1`
done

hope this helps!
kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Ernesto Cappello
Trusted Contributor

Re: Set a ping program

Hi hangyu

This is "ping_host.csh" script
#!/bin/csh -f
/usr/sbin/ping -s HOSTNAME

This is kill_ping.csh script:
#!/bin/csh -f
set PR_ID = `/bin/ps -ef | grep ping | grep -v grep | grep HOSTNAME | awk '{print $2}'`
kill -9 $PR_ID

This is crontab line:

00 9 * * 1-5 ping_host.csh > ping.log 2>&1
00 17 * * 1-5 kill_ping.csh

Best Regards
Ernesto.