Placeholder for our stuff related to Telecom, IT, Internet of things (IOT), ESP8266, Raspberry Pi
This script will ping specified host periodically and display the result. You can save results to a logfile. I will show you how you can run this script unattended so that output will keep logging in a file even-if you close your ssh/telnet session.
This will help you capture intermittent ping drops between two nodes.
The script will send one ping every second and display the result on screen. You can increase the sleep time as per your requirement by changing "sleep 1". For example "sleep 5" will send one ping every 5 seconds.
Make the script executable by following command
chmod +x myPingScript.sh
To capture result in a log file use linux output redirection
./myPingScript.sh 10.40.2.34 >> myLogFile.txt &
If you are interested in capturing only down times then use grep.
./myPingScript.sh 10.40.2.34 | grep down >> myLogFile.txt
To get the output on the console AND in a file
./myPingScript.sh 10.40.2.38 | tee myLogFile.txt
Ensure that you have write permissions on filepath.
Running script in background
Running script with nohup will keep it running in background.
nohup command line-utility allows to run command/process or shell script that can continue running in the background after you log out from a shell.
nohup ./myPingScript.sh 10.40.2.38 | grep down >> myLogFile.txt