0

I'm trying to write a bash script which will do the following

Read a file that has IP addresses stored in it ips.txt

Take those IP addresses and break them into 3 variables that write to their own files

Files
    thrid_octave.txt
    last_digit_third_octave.txt
    last_octive.txt

Variables 
    thrid_octave
    last_digit_third_octave
    last_octive

EX: 12.34.117.88

    thrid_octave = 111
    last_digit_third_octave = 7
    last_octive = 88

Below is how i intend to use those variables

    #!/bin/bash
    domain="$(cat domains.txt)"
    ip="$(cat ips.txt)"
    last_number_third_octete="$(cat last_number_third_octete.txt)"
    thrid_octive="$(cat thrid_octive.txt)"
    last_octive="$(cat last_octive.txt)"

    while read -r domain <&3 && read ip <&4 && read last_number_third_octete <&5 && read thrid_octive <&6 && read last_octive <&7 &&; 
    do 
    echo "processing $domain";


    "##################################### $domain ######################################################"
    smtp-listener $ip\n

    <virtual-mta $domain.c$last_number_third_octete.$last_octive>
    smtp-source-host $ip mailer1-vmta-plat-$thrid_octive-$last_octive.$domain
    </virtual-mta>

    <virtual-mta-pool $domain.p>
    virtual-mta $domain.c$thrid_octive-$last_octive
    </virtual-mta-pool>

    \n\n

    done 3<domains.txt 4<ips.txt 5<last_number_third_octete.txt 6<thrid_octive.txt 7<last_octive.txt

    echo "All Set"
Dennis
  • 21
  • 6

1 Answers1

0

You could try to use cut, like this:

ip="12.34.117.88"
thrid_octave=`echo $ip | cut -d\. -f3`
last_digit_third_octave=`echo $ip | cut -d\. -f3 | cut -c 3`
last_octive=`echo $ip | cut -d\. -f4`
frank
  • 1,007
  • 1
  • 6
  • 13