Find the answer to your Linux question:
Results 1 to 2 of 2
So, I'm trying to build a script for my place of employment. I'm building it in pieces. Right now, I've been stuck on a piece for a bit, getting closer ...
  1. #1
    Just Joined!
    Join Date
    Jul 2009
    Posts
    24

    IP script assist

    So, I'm trying to build a script for my place of employment. I'm building it in pieces. Right now, I've been stuck on a piece for a bit, getting closer and closer to the end by guess and check. But now, I have no clue where to start this next one.

    I'm trying to make it so the user inputs the CIDR and it calculates the gateway, and first and last usable IP. Right now, it only works for a /29. I'm trying to make it so it creates multiple virtual IPs. so ifcfg-eth1:1 1:2 1:3 etc. Until it gets to the last IP. Right now, I have:

    #!/bin/bash

    echo -n "Enter IP: "
    read IP;
    num=1

    echo Gateway: "$IP" | awk -F "." '{print $1 "." $2 "." $3 "." ($4+1);}'
    echo First Usable IP: "$IP" | awk -F "." '{print $1 "." $2 "." $3 "." ($4+2);}'
    echo Last Usable IP: "$IP" | awk -F "." '{print $1 "." $2 "." $3 "." ($4+7);}'

    echo > echotest
    echo GATEWAY="$IP" | awk -F "." '{print $1 "." $2 "." $3 "." ($4+1)}' >> echotest
    echo IPADDR="$IP" | awk -F "." '{print $1 "." $2 "." $3 "." ($4+2+$num)}' >> ./echotest


    This just calculates the gateway and first and last and echos the first usable IP and the gateway into a file called echotest. How do I get it to keep creating the files until it hits the last usable IP?

    Thanks!!

  2. #2
    Linux User
    Join Date
    Nov 2009
    Location
    France
    Posts
    292
    This page may be of interest to you : LAFFEY: whatmask
    0 + 1 = 1 != 2 <> 3 != 4 ...
    Until the camel can pass though the eye of the needle.

Posting Permissions

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