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-24-2008
Lasthitlarry Lasthitlarry is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 6
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--
  #2 (permalink)  
Old 10-24-2008
sethcoop sethcoop is offline
Registered User
  
 

Join Date: Oct 2008
Location: United States
Posts: 34
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
  #3 (permalink)  
Old 10-24-2008
avis1981 avis1981 is offline
Registered User
  
 

Join Date: Oct 2008
Location: NC
Posts: 21
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
  #4 (permalink)  
Old 10-24-2008
Lasthitlarry Lasthitlarry is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 6
Quote:
Originally Posted by avis1981 View Post
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!
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 06:26 PM.


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