View Full Version : Simple shell script to ping every couple of minutes?
hypersire
May 7th, 2007, 06: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 7th, 2007, 07:26 PM
This is an infinite loop in Bash:
while [ 1 ]; do
# Commands here.
done
hypersire
May 7th, 2007, 11:43 PM
Thanks very much Ayman!
bashologist
May 7th, 2007, 11:57 PM
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, 03:14 PM
what about a simply using the interval switch
ping -i120 ipaddress
hypersire
May 9th, 2007, 11:55 AM
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, 12:37 PM
Cron it.
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.