View Full Version : Simple shell script to ping every couple of minutes?
hypersire
May 7th, 2007, 11:52 PM
Hi all - I keep getting kicked off my remote desktop connection (due to inactivity) so I am trying to write a little shell script that will simply ping the remote computer every 2 minutes.
ping -c 4 ipaddress
sleep 120
repeat
What code could I use to repeat the ping every 2 minutes?
Thanks!
Ayman
May 8th, 2007, 12:26 AM
This is an infinite loop in Bash:
while [ 1 ]; do
# Commands here.
done
hypersire
May 8th, 2007, 04:43 AM
Thanks very much Ayman!
bashologist
May 8th, 2007, 04:57 AM
A few other ways of doing an infinite loop:
for ((;;)) do
echo "enter commands here"
sleep 120
done
while true; do
echo "enter commands here"
sleep 120
done
DeadEyes
May 8th, 2007, 08:14 PM
what about a simply using the interval switch
ping -i120 ipaddress
hypersire
May 9th, 2007, 04:55 PM
what about a simply using the interval switch
ping -i120 ipaddress
Even better! I didn't know about the ping interval switch! Thanks!
The only benefit to using the shell script with a loop and and the count flag is that the ping operation completes each iteration, showing you the full stats. With the -i method you won't see the full stats till you end the operation. I don't care about the stats so I am using the ping -i method.
And it works great - my remote desktop connection no longer kicks me off! I just ping the server every 5 minutes.
bLUEbYTE
May 9th, 2007, 05:37 PM
Cron it.
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.