The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 06: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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-23-2008
Lasthitlarry Lasthitlarry is offline
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.
  #2 (permalink)  
Old 10-23-2008
glen.barber glen.barber is offline
Registered User
  
 

Join Date: May 2008
Location: Philadelphia, PA, USA
Posts: 117
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?
  #3 (permalink)  
Old 10-23-2008
Lasthitlarry Lasthitlarry is offline
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
  #4 (permalink)  
Old 10-23-2008
glen.barber glen.barber is offline
Registered User
  
 

Join Date: May 2008
Location: Philadelphia, PA, USA
Posts: 117
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.
  #5 (permalink)  
Old 10-23-2008
avis1981 avis1981 is offline
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
  #6 (permalink)  
Old 10-24-2008
Lasthitlarry Lasthitlarry is offline
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?
  #7 (permalink)  
Old 10-24-2008
sethcoop sethcoop is offline
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:10 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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