![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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-- |
|
||||
|
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
|
|
||||
|
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 |
|
||||
|
Quote:
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! |
| Sponsored Links | ||
|
|