Need help with simple script | Unix Linux Forums | UNIX Desktop for Dummies Questions & Answers

  Go Back    


UNIX Desktop for Dummies Questions & Answers Discuss UNIX and Linux user interfaces like GNOME, KDE, CDE, and Open Office here. All UNIX and Linux Newbies Welcome !!

Need help with simple script

UNIX Desktop for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-08-2013
LelandSelene LelandSelene is offline
Registered User
 
Join Date: Oct 2013
Last Activity: 15 October 2013, 6:23 PM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Need help with simple script

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.


Code:
echo 'What IP address would you like to ping?'
read VAR_1
echo "Pinging $VAR_1..."

if [ -t 0 ]; then stty -echo -icanon time 0 min 0; fi

{
count=0
keypress=''
while [ "x$keypress" = "x" ]; do
  echo "
  THE TIME IS: $(date)"
  ping -c 20 $VAR_1
done
} > /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."

VAR_2=$VAR_12
grep 'TIME\|packet' /home/tyler/Programs/Pinglog\ Results/$VAR_1.txt > $VAR_2.txt

exit 0


Last edited by Scrutinizer; 10-08-2013 at 12:27 PM.. Reason: code tags
Sponsored Links
    #2  
Old 10-08-2013
rbatte1 rbatte1 is offline Forum Staff  
Moderator
 
Join Date: Jun 2007
Last Activity: 28 August 2014, 12:49 PM EDT
Location: Lancashire, UK
Posts: 1,754
Thanks: 561
Thanked 298 Times in 267 Posts
Have you looked at this thread:-
http://www.unix.com/unix-dummies-que...-function.html
I learned a lot for making mistakes and reading what was being done here and the explanations given of my errors.


Robin
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help making simple perl or bash script to create a simple matrix torchij Shell Programming and Scripting 16 04-26-2012 04:05 AM
please help me in a simple script ali560045 Shell Programming and Scripting 1 05-05-2009 05:30 AM
Simple script chvs2000 UNIX for Dummies Questions & Answers 4 12-30-2008 11:39 AM
simple script ali560045 Shell Programming and Scripting 1 01-22-2008 03:41 AM
help with simple script jdel80 UNIX for Dummies Questions & Answers 1 11-29-2005 11:44 AM



All times are GMT -4. The time now is 01:17 AM.