Ping text file of ip addressese and output to text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ping text file of ip addressese and output to text file
# 1  
Old 10-23-2008
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  
Old 10-23-2008
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  
Old 10-23-2008
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  
Old 10-23-2008
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  
Old 10-23-2008
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  
Old 10-24-2008
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  
Old 10-24-2008
Quote:
Originally Posted by Lasthitlarry

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Shell Programming and Scripting

Diff output to text file

Hi All, When I write the diff command output(side by side format) to a file and viewed on the desktop using any text editor(say Notepad) the format of the output layout isn't the same as it should be, though "Wordwrap" option is disabled. Which means left and right records are not on same line.... (0 Replies)
Discussion started by: Badhrish
0 Replies

3. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

4. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

5. Shell Programming and Scripting

Compare two text file and output the same to third file

Need help. I have a source file that listed sets of numbers/words and what i'm trying to do is, by each line of the source file i want to look for same numbers/words in second file and if it match then write it to third file. Third file should have whole line from source file plus whole line... (7 Replies)
Discussion started by: suresh7730
7 Replies

6. UNIX for Dummies Questions & Answers

Converting a text file with irregular spacing into a space delimited text file?

I have a text file with irregular spacing between values which makes it really difficult to manipulate. Is there an easy way to convert it into a space delimited text file so that all the spaces, double spaces, triple spaces, tabs between numbers are converted into spaces. The file looks like this:... (5 Replies)
Discussion started by: evelibertine
5 Replies

7. Shell Programming and Scripting

search text file in file if this file contains necessary text (awk,grep)

Hello friends! Help me pls to write correct awk and grep statements for my task: I have got files with name filename.txt It has such structure: Start of file FROM: address@domen.com (12...890) abc DATE: 11/23/2009 on Std SUBJECT: any subject End of file So, I must check, if this file... (4 Replies)
Discussion started by: candyme
4 Replies

8. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

9. Shell Programming and Scripting

Create multiple text file from a single text file on AIX

Hi I need to create multiple text files from onc text file on AIX. The data of text files is as below: ********************************************** ********************************************** DBVERIFY: Release 10.2.0.4.0 - Production on Tue Nov 10 13:45:42 2009 Copyright (c) 1982,... (11 Replies)
Discussion started by: lodhi1978
11 Replies

10. Shell Programming and Scripting

how can I bcp out a table into a text file including the header row in the text file

Hi All, I need to BCP out a table into a text file along with the table headers. Normal BCP out command only bulk copies the data, and not the headers. I am using the following command: bcp database1..table1 out file1.dat -c -t\| -b1000 -A8192 -Uuser -Ppassword -efile.dat.err Regards,... (0 Replies)
Discussion started by: shilpa_acc
0 Replies
Login or Register to Ask a Question