Professional Web Applications Themes

I need a script - UNIX Programming

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` > ...

  1. #1

    Default I need a script

    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?



    Joshua Guest

  2. #2

    Default Re: I need a script

    In article <FDU%b.106273$nbnet.nb.ca>,
    "Joshua Sparks" <sympatico.ca> wrote:
     

    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, mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    Barry Guest

  3. #3

    Default Re: I need a script

    Joshua Sparks wrote: 

    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
    John Guest

  4. #4

    Default Re: I need a script

    Joshua Sparks <sympatico.ca> wrote: 

    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, <ca>
    Linux solution for data management and processing.
    William Guest

  5. #5

    Default Re: I need a script

    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" <mit.edu> wrote in message
    news:ash.giganews.com... [/ref]
    a [/ref]
    script [/ref]
    results. [/ref]
    that [/ref]
    option [/ref]
    awk [/ref]
    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, mit.edu
    > Arlington, MA
    > *** PLEASE post questions in newsgroups, not directly to me ***[/ref]


    Joshua Guest

  6. #6

    Default Re: I need a script

    Joshua Sparks wrote:
     

    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 <de>
    \__ \ _/ -_) V / -_) ' \ Shell Script Programmers: visit
    |___/\__\___|\_/\___|_||_| http://www.shelldorado.com/
    Heiner Guest

  7. #7

    Default Re: I need a script

    In article <4Cr0c.107167$nbnet.nb.ca>,
    "Joshua Sparks" <sympatico.ca> wrote:
     

    Nothing in my script was bash-dependent.
     

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

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

Similar Threads

  1. ksh script - Preventing multiple runs of a particular script
    By Melissa in forum Linux / Unix Administration
    Replies: 4
    Last Post: June 26th, 01:49 PM
  2. 6.1 script not working on 7.0 server. Script used towork!
    By piaposa in forum Coldfusion Flash Integration
    Replies: 1
    Last Post: February 9th, 03:43 PM
  3. Replies: 2
    Last Post: January 24th, 06:00 AM
  4. Execute shell script from a perl script
    By kderaedt in forum Perl / CGI
    Replies: 3
    Last Post: June 26th, 08:26 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139