I need a script
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > I need a script




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    I need a script  
Joshua Sparks


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-28-04 04:33 AM

I use a bash shell (cygwin) out to my PC so I can do Unix stuff.  I have a
file of IP addresses that I want to feed into tracert.  So I build a script
that takes in $1 and $2 where $1 is the input file and $2 is the results.
Basically, I need to take $1, do a sort -u (for uniqueness) and feed that
into the tracert program which comes with Windows XP so I can do a batch
trace.  The command I've come up with is:

sort -u $1 > sorted_$1
tracert -j `cat sorted_$1` > $2

but this doesn't work.  It says either an ambiguous list or that the option
is too large.  The only alternative is to do something in PERL or sed or awk
to add the tracert to the beginning of each line of the sorted file and spit
the results out there.  Any ideas?








[ Post a follow-up to this message ]



    Re: I need a script  
Barry Margolin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-28-04 06:33 AM

In article <FDU%b.106273$IF6.3220710@ursa-nb00s0.nbnet.nb.ca>,
"Joshua Sparks" <nacs@nb.sympatico.ca> wrote:

> I use a bash shell (cygwin) out to my PC so I can do Unix stuff.  I have a
> file of IP addresses that I want to feed into tracert.  So I build a scrip
t
> that takes in $1 and $2 where $1 is the input file and $2 is the results.
> Basically, I need to take $1, do a sort -u (for uniqueness) and feed that
> into the tracert program which comes with Windows XP so I can do a batch
> trace.  The command I've come up with is:
>
> sort -u $1 > sorted_$1
> tracert -j `cat sorted_$1` > $2
>
> but this doesn't work.  It says either an ambiguous list or that the optio
n
> is too large.  The only alternative is to do something in PERL or sed or a
wk
> to add the tracert to the beginning of each line of the sorted file and sp
it
> the results out there.  Any ideas?

That command will run tracert one time with *all* the IP addresses as
parameters, it won't run it multiple times.  You need to write a loop,
e.g.

for ip in `sort -u $1`
do
tracert -j $ip
done > $2

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***





[ Post a follow-up to this message ]



    Re: I need a script  
John W. Krahn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-28-04 06:33 AM

Joshua Sparks wrote:
>
> I use a bash shell (cygwin) out to my PC so I can do Unix stuff.  I have a
> file of IP addresses that I want to feed into tracert.  So I build a scrip
t
> that takes in $1 and $2 where $1 is the input file and $2 is the results.
> Basically, I need to take $1, do a sort -u (for uniqueness) and feed that
> into the tracert program which comes with Windows XP so I can do a batch
> trace.  The command I've come up with is:
>
> sort -u $1 > sorted_$1
> tracert -j `cat sorted_$1` > $2
>
> but this doesn't work.  It says either an ambiguous list or that the optio
n
> is too large.  The only alternative is to do something in PERL or sed or a
wk
> to add the tracert to the beginning of each line of the sorted file and sp
it
> the results out there.  Any ideas?

Untested!:

#!/usr/bin/perl

@ARGV == 2 or die "Usage: $0 input_file results_file\n";
$results_file = pop;  # remove results file from @ARGV

open OUT, '>', $results_file or die "Cannot open $results_file: $!";

@addresses = grep !$found{ $_ }++, grep [ chomp ], <>;

print OUT `tracert -j $_` foreach sort @addresses;

__END__



John
--
use Perl;
program
fulfillment





[ Post a follow-up to this message ]



    Re: I need a script  
William Park


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-28-04 07:33 PM

Joshua Sparks <nacs@nb.sympatico.ca> wrote:
> I use a bash shell (cygwin) out to my PC so I can do Unix stuff.  I have a
> file of IP addresses that I want to feed into tracert.  So I build a scrip
t
> that takes in $1 and $2 where $1 is the input file and $2 is the results.
> Basically, I need to take $1, do a sort -u (for uniqueness) and feed that
> into the tracert program which comes with Windows XP so I can do a batch
> trace.  The command I've come up with is:
>
> sort -u $1 > sorted_$1
> tracert -j `cat sorted_$1` > $2
>
> but this doesn't work.  It says either an ambiguous list or that the optio
n
> is too large.

1.  sort -u $1 | while read IP; do
tracert -j $IP
done > $2

2.  sort -u $1 | xargs -l1 tracert -j > $2

--
William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
Linux solution for data management and processing.





[ Post a follow-up to this message ]



    Re: I need a script  
Joshua Sparks


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-29-04 08:34 PM

I'm actually going to use the Uwin ksh system to use a korn shell interface.
bash is too "unfamiliar".  Anyway, here's what I came up with

#!/usr/bin/ksh
grep "^Remote" $1 | grep "local service is" | grep -v "ftp" |
/usr/bin/cut -c34-55 > temp1
/usr/bin/awk -F, '{ print $1 }' temp1 > temp2
/usr/bin/sort -u temp2 > temp3
for ip in `/usr/bin/cat temp3`
do
tracert $ip
done > $2
rm -f temp*

This program takes the "Firewall" tab of Norton Internet Security, which you
have saved toa text file as input $1 and processes it to
find all the unique IP addresses of suspicious activities and runs a trace
route on them.  If anyone else wants to use it, feel free.

"Barry Margolin" <barmar@alum.mit.edu> wrote in message
news:barmar-FCDD1C.00584628022004@comcast.ash.giganews.com...
> In article <FDU%b.106273$IF6.3220710@ursa-nb00s0.nbnet.nb.ca>,
>  "Joshua Sparks" <nacs@nb.sympatico.ca> wrote:
> 
a 
script 
results. 
that 
option 
awk 
spit 
>
> That command will run tracert one time with *all* the IP addresses as
> parameters, it won't run it multiple times.  You need to write a loop,
> e.g.
>
> for ip in `sort -u $1`
> do
>   tracert -j $ip
> done > $2
>
> --
> Barry Margolin, barmar@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***







[ Post a follow-up to this message ]



    Re: I need a script  
Heiner Steven


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-29-04 10:33 PM

Joshua Sparks wrote:

> I'm actually going to use the Uwin ksh system to use a korn shell interfac
e.
> bash is too "unfamiliar".  Anyway, here's what I came up with
>
> #!/usr/bin/ksh
> grep "^Remote" $1 | grep "local service is" | grep -v "ftp" |
> /usr/bin/cut -c34-55 > temp1
> /usr/bin/awk -F, '{ print $1 }' temp1 > temp2
> /usr/bin/sort -u temp2 > temp3
> for ip in `/usr/bin/cat temp3`
> do
>   tracert $ip
> done > $2
> rm -f temp*

Without knowing the format of the input file "$1"
the script can still be changed to not need any temporary
file:

#! /usr/bin/ksh
grep '^Remote.*local service is" "$1" |
grep -v ftp |
cut -c34-55 |
cut -d, -f1 |
sort -u |
while read ip
do
tracert "$ip"
done

The "grep -v" and the "cut" commands maybe could be optimized,
too, but for this we'd need to know how an example input
file looks like.

Heiner
--
___ _
/ __| |_ _____ _____ _ _     Heiner STEVEN <heiner.steven@nexgo.de>
\__ \  _/ -_) V / -_) ' \    Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_|   http://www.shelldorado.com/





[ Post a follow-up to this message ]



    Re: I need a script  
Barry Margolin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-01-04 02:33 AM

In article <4Cr0c.107167$IF6.3278378@ursa-nb00s0.nbnet.nb.ca>,
"Joshua Sparks" <nacs@nb.sympatico.ca> wrote:

> I'm actually going to use the Uwin ksh system to use a korn shell interfac
e.
> bash is too "unfamiliar".  Anyway, here's what I came up with

Nothing in my script was bash-dependent.

>
> #!/usr/bin/ksh
> grep "^Remote" $1 | grep "local service is" | grep -v "ftp" |
> /usr/bin/cut -c34-55 > temp1
> /usr/bin/awk -F, '{ print $1 }' temp1 > temp2
> /usr/bin/sort -u temp2 > temp3
> for ip in `/usr/bin/cat temp3`
> do
>   tracert $ip
> done > $2
> rm -f temp*

Why do you need all those temp files?  Just pipe everything together.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 08:44 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register