The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Adding specific text and spaces to each line in a text file hertingm Shell Programming and Scripting 4 08-25-2008 02:34 PM
parse through one text file and output many sophiadun UNIX for Dummies Questions & Answers 14 02-20-2008 05:08 AM
Extract text in 2 columns of output file. Danish Shakil Shell Programming and Scripting 2 10-19-2007 10:03 AM
I want to copy the text output from a 'nohup.out' file. Iamthe great UNIX for Dummies Questions & Answers 3 05-01-2007 12:41 PM
grep multiple text files in folder into 1 text file? coppertone UNIX for Dummies Questions & Answers 7 08-23-2002 02:50 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-23-2008
Registered User
 

Join Date: Oct 2008
Posts: 6
Ping text file of ip addressese and output to text file

I am basically a scripting noob, I have some programming logic, and I wouldn't post here if my 3 hours of searching actually found something.

So far this is what I have:

"

#! /bin/ksh
List=./pinglist1.txt

cat $List | while read ip
do
Pingable=""
ping $ip -n 2 | awk '/100%/ {print "no"}' |read Pingable
if [[ "$Pingable" != "no" ]]
then
print $ip "PINGS">>pingresults.txt
else
print $ip "DOESN'T PING">>pingresults.txt
fi
done

"

pinglist1.txt is just a plain file with IP addresses.

I just want the script to ping each IP address and report if it is pinging or not to a text file.

Please and thanks.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-23-2008
Registered User
 

Join Date: May 2008
Location: Philadelphia, PA, USA
Posts: 113
Could you provide the output of your script?

Also, the 'dotslash' isn't necessary in
Code:
List=./pinglist1.txt
as './' tells the shell to use the $PWD.

Is the pinglist1.txt file in the same directory as the script?
Reply With Quote
  #3 (permalink)  
Old 10-23-2008
Registered User
 

Join Date: Oct 2008
Posts: 6
I went ahead and got rid of the ./

and yes, the .txt is in the same directory

These are the results:

usage: ping [-LRdfmnqrtv] [-T ttl] [-I addr] [-c count] [-i wait] [-l preload]
[-p pattern] [-s packetsize] host|[!]@hop1@hop2@...[@|:]dst
UX:sh (ping.sh): ERROR: [[: not found
UX:sh (ping.sh): ERROR: print: not found
usage: ping [-LRdfmnqrtv] [-T ttl] [-I addr] [-c count] [-i wait] [-l preload]
[-p pattern] [-s packetsize] host|[!]@hop1@hop2@...[@|:]dst
UX:sh (ping.sh): ERROR: [[: not found
UX:sh (ping.sh): ERROR: print: not found
usage: ping [-LRdfmnqrtv] [-T ttl] [-I addr] [-c count] [-i wait] [-l preload]
[-p pattern] [-s packetsize] host|[!]@hop1@hop2@...[@|:]dst
UX:sh (ping.sh): ERROR: [[: not found
UX:sh (ping.sh): ERROR: print: not found
usage: ping [-LRdfmnqrtv] [-T ttl] [-I addr] [-c count] [-i wait] [-l preload]
[-p pattern] [-s packetsize] host|[!]@hop1@hop2@...[@|:]dst
UX:sh (ping.sh): ERROR: [[: not found
UX:sh (ping.sh): ERROR: print: not found
Reply With Quote
  #4 (permalink)  
Old 10-23-2008
Registered User
 

Join Date: May 2008
Location: Philadelphia, PA, USA
Posts: 113
Well, I have minimal experience with shell scripting, but from the output, I see that it's erroring that your `ping' syntax is incorrect. Analyzing the script, you have the IP address of the host before `-n 2', which I believe to be incorrect.

Either way, I cannot help with `awk' syntax.
Reply With Quote
  #5 (permalink)  
Old 10-23-2008
Registered User
 

Join Date: Oct 2008
Location: NC
Posts: 21
Looks more like ping syntax

Are you trying to do 2 echoes to ip, if so

ping -c 2 $ip | awk '/100%/ {print "no"}' |read Pingable
Reply With Quote
  #6 (permalink)  
Old 10-24-2008
Registered User
 

Join Date: Oct 2008
Posts: 6
Thanks, now I can tell it is running the ping, and I went ahead and modified my code to this now:

#! /bin/ksh
List=pinglist1.txt

cat $List | while read ip
do
Pingable=""
ping -c 2 $ip | awk '/100%/ {print "no"}' |read Pingable
if [ "$Pingable" != "no" ]
then
print $ip "PINGS">>pingresults.txt
else
print $ip "DOESN'T PING">>pingresults.txt
fi
done


AND the results:
UX:sh (ping1.sh): ERROR: print: not found

Do I need to have a print.pl or something uploaded to that directory?
Reply With Quote
  #7 (permalink)  
Old 10-24-2008
Registered User
 

Join Date: Oct 2008
Location: United States
Posts: 34
Quote:
Originally Posted by Lasthitlarry View Post

AND the results:
UX:sh (ping1.sh): ERROR: print: not found

Do I need to have a print.pl or something uploaded to that directory?

try echo...

Code:
 
  echo "$ip PINGS" >> pingresults.txt
else
  echo "$ip DOESN'T PING" >> pingresults.txt
Reply With Quote
Google The UNIX and Linux Forums
Reply

Bookmarks

Tags
None

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 08:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66