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
# 8  
Old 10-24-2008
Appreciate the responses, so far I am trying to read up on what to do next, the problems I am facing are I need to know how to step to the next line in the text file, and the results I got so far are troubling. I have 2 ip addresses so far in the text file, when the IP address that pings is first in the list, it prints:

--IP address 1-- PINGS

but when I have an IP address that doesnt ping first in the list it prints:

--IP address 2-- PINGS

I also modified my code to delete the results file at the start of the script

EDIT: I have removed the real IP addresses and just have them named --IP address 1-- and --IP address 2--
# 9  
Old 10-24-2008
Give this a shot...

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

cat $List | while read ip
do

  ping -c 2 $ip
  rc=$?
 
  if [[ "$rc" = "0" ]]
  then
    echo "$ip PINGS">>pingresults.txt
  else
    echo "$ip DOESN'T PING">>pingresults.txt
  fi
done

# 10  
Old 10-24-2008
Thanks.

Ya, unfortunately I'm having the same problem, both programs just ping the first in the file and then quits.

I need to know how to step to the next line -a loop basically-(I am reading up on it as well)
# 11  
Old 10-24-2008
Can you try this one:

#! /bin/ksh
IPLIST=`cat ./pinglist1.txt`
for ip in $IPLIST
do
echo $ip
ping -c 2 $ip >>log.txt
if [[ $? -eq 0 ]]
then
print $ip "PINGS">>pingresults.txt
else
print $ip "DOESN'T PING">>pingresults.txt
fi
done
# 12  
Old 10-24-2008
Quote:
Originally Posted by avis1981
Can you try this one:

#! /bin/ksh
IPLIST=`cat ./pinglist1.txt`
for ip in $IPLIST
do
echo $ip
ping -c 2 $ip >>log.txt
if [[ $? -eq 0 ]]
then
print $ip "PINGS">>pingresults.txt
else
print $ip "DOESN'T PING">>pingresults.txt
fi
done
THANKS.

I just had to modify it a bit, changed [[ ]] to [ ] and print to echo and it worked.

pingresults.txt produced the following (xxx for security purposes):

xxx.xxx.193.16 DOESN'T PING
xxx.xxx.135.194 PINGS

Thanks!
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