I work for a small internet company, and sometimes its useful to ping a certain IP over an open amount of time. I wrote a simple script that asks what IP you'd like to ping, and then pings it and puts it into a text file so that you can save the results. What i'd like though, is to have an infinite loop that pings and puts it into a text file, and then, after a certain key is pressed, it stops that part of the script and continues on to the next part, that uses Grep, and filters out the pings so that you just get the time, and and the end part of the ping, where it tells you packet loss and such. This is what I have so far. I know it is likely completely wrong, I'm new to this, and this is what I have combining my script and what I think I want from googling how to use user input to end an infinite loop.
echo 'What IP address would you like to ping?'
echo "Pinging $VAR_1..."
if [ -t 0 ]; then stty -echo -icanon time 0 min 0; fi
while [ "x$keypress" = "x" ]; do
THE TIME IS: $(date)"
ping -c 20 $VAR_1
} > /home/tyler/Programs/Pinglog\ Results/$VAR_1.txt
if [ -t 0 ]; then stty sane; fi
echo "You pressed '$keypress' after $count loop iterations"
echo "Thanks for using this scipt."
grep 'TIME\|packet' /home/tyler/Programs/Pinglog\ Results/$VAR_1.txt > $VAR_2.txt