Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Need help for a bash script - OVZ container
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Need help for a bash script - OVZ container

TazTaz Member
edited September 2012 in General

So, I am writing a simple setup script for ovz container (bash code?), Right now I am stuck at one place,

I have a configuration file that goes like this

Herpy Derp

derp derp
derpy derp
serverip= #
blah blah
blah blah

So now, I need something that would do this

echo serverip= x.x.x.x > /etc/service.conf

and

iptables -t nat -A POSTROUTING -s 1.2.3.0/24 -j SNAT --to "serverip"

How would the script find and replace server ip for both case?

Comments

  • @Taz_NinjaHawk said: I have a configuration file that goes like this

    Herpy Derp

    derp derp
    derpy derp
    serverip= #
    blah blah
    blah blah

    Is this a template? And you want to replace # with the server ip?

    So now, I need something that would do this

    echo serverip= x.x.x.x > /etc/service.conf

    Or is 'service.conf' the above?

    Sorry, it's really unclear to me what the flow is supposed to be....

  • TazTaz Member
    edited September 2012

    Kinda,
    Is there anyway to echo servers main ip inside that config file using commands like ip addr show?

  • Well

    serverip= #

    would be replaced by

    serverip= x.x.x.x

  • @Zen said: Yeah but you're still being unclear what the objective is entirely, just tell us exactly what you want us to do in order.

    This is for an auto setup openvpn script.

  • "Is there anyway to echo servers main ip inside that config file using commands like ip addr show"

    OT: I don't know, I will re-read the thread tomorrow and see if i can help you, I am tired. :-(

    @Zen said: just tell us exactly what you want us to do in order.

    Thanked by 1Taz
  • prometeusprometeus Member, Host Rep
    box:~# cat testreplace 
    jdie
    diejihurhu
    goirogor
    ofrkfor
    serverip=#
    ekdkeoi
    
    box:~# a=1.1.1.1 ;sed -e "s/=#/=$a/" testreplace 
    jdie
    diejihurhu
    goirogor
    ofrkfor
    serverip=1.1.1.1
    ekdkeoi
    

    if you place inside a script you can pass a parameter:

    #!/bin/sh
    a=$1
    sed -e "s/=#/=$a/" /path/to/template
    
  • I only guessing still at what you want, but...

    template.txt

    Herpy Derp
    derp derp
    derpy derp
    serverip=#SERVERIP#
    blah blah
    blah blah

    script.sh

    #!/bin/bash
    
    SERVERIP=$1
    TEMPLATE=`cat template.txt`
    
    if [ "$SERVERIP" ]; then
        CONFIG=`echo "$TEMPLATE" | sed "s/#SERVERIP#/$SERVERIP/"`
        echo "$CONFIG"
    else
        echo "Usage: script.sh [ip address]"
    fi
    
    exit 0

    Usage:

    [sleddog@home:~/test] sh script.sh 192.168.1.100
    Herpy Derp
    derp derp
    derpy derp
    serverip=192.168.1.100
    blah blah
    blah blah
    Thanked by 1Taz
  • I could write it for you, but that would be cheating, use a foreach line statement and awk. If I recall properly you can parse until $1 is your serverip, then read $3 and then that's your IP.

  • DewlanceVPSDewlanceVPS Member, Patron Provider

    [ninja.hawk.kid.server]#school
    this is professional
    exist and
    go to school ninja_hawk

  • DewlanceVPSDewlanceVPS Member, Patron Provider

    lol, you're promoting our company at free of cost.

    • Free direct back-link
    • Free +PR
    • Free Marketing..

    Thanks Ninja_Hawk

  • TazTaz Member
    edited September 2012

    @DewlanceVPS said: lol, you're promoting our company at free of cost.

    Free direct back-link

    Free +PR
    Free Marketing..
    Thanks Ninja_Hawk

    You are most welcome kind sir. Now it would be nice if you stop using burstnet before we all get into this dirty game.

  • DewlanceVPSDewlanceVPS Member, Patron Provider

    Thanks Ninja_Hawk, Now I did not hate you.

    Who help you to write this post? profile link?

  • InfinityInfinity Member, Host Rep

    @DewlanceVPS said: Free Marketing..

    It's better marketing than you could ever dream of doing.

    Unless your clients are as dumb as you they'll know not to touch your farcical "company" with a barge pole.

  • DewlanceVPSDewlanceVPS Member, Patron Provider

    @Infinity said: It's better marketing than you could ever dream of doing.

    Unless your clients are as dumb as you they'll know not to touch your farcical "company" with a barge pole.

    I don't need your Suggestion :)

  • AlexBarakovAlexBarakov Patron Provider, Veteran
    edited September 2012

    @DewlanceVPS

    You make me LOL. :(

  • Still going to use Burstnet kunnu?

    Thanked by 1DeletedUser
  • DewlanceVPSDewlanceVPS Member, Patron Provider

    @Ninja_Hawk

    Shame on you, you are DDoSing our server?

  • @DewlanceVPS said: Shame on you, you are DDoSing our server?

    Are you kiddin me? I don't play stupid shit. Post your log. BTW, only your site is out while the whole server is up. Trying to frame some one kiddo :P

  • Here is an OpenVPN script you can make use of: http://vpsnoc.com/blog/tag/openvpn/

Sign In or Register to comment.