Please note that LinuxExchange will be shutting down on December 31st, 2016. Visit this thread for additional information and to provide feedback.

Dear All,

I have small query for Linux Shell Scripting , below is my requirement:

I have configured dnsmasq.conf , and it is working fine , I want to create script which automatically change the configuration of sever based on small input from user:

dhcp-range=192.168.4.200,192.168.4.230,2h

From this line I want to change start range and end range by script,This IP will not be fix all the time so I can not use "192.168.4.200" in my script with sed , I want to put 192.168.4.200 (or any IP there on dhcp-range line with variable $startip) and 192.168.4.230 with (variable $endip)

I tried using grep -o '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}' and also tried with awk but till now no success.

asked 27 Jul '10, 14:26

Chetan%20Diwani's gravatar image

Chetan Diwani
123
accept rate: 0%

edited 27 Jul '10, 21:47

Jazz's gravatar image

Jazz ♦
7811312

Please accept an answer so the question/answer can be finished. Or provide more details so we can help.

(20 Apr '11, 14:12) rfelsburg ♦



Something like this what you're thinking?

[felsburr@agnus ~]$ cat /tmp/dnsmasq.conf
dhcp-range=192.168.4.200,192.168.4.230,2h

[felsburr@agnus tmp]$ ./dnsMasqUpdate 192.168.0.1 192.168.0.100

[felsburr@agnus tmp]$ cat dnsmasq.conf
dhcp-range=192.168.0.1,192.168.0.100,2h


[felsburr@agnus tmp]$ cat ./dnsMasqUpdate
#!/bin/bash

PATH=/bin:/sbin:/usr/bin:/usr/sbin
_sed=/bin/sed

dnsConfFile=/tmp/dnsmasq.conf

startip=${1}
endip=${2}

$_sed -i "s/^dhcp-range=.*/dhcp-range=${startip},${endip},2h/" ${dnsConfFile}
link

answered 27 Jul '10, 15:00

rfelsburg's gravatar image

rfelsburg ♦
6061618
accept rate: 25%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×90
×16
×9

Asked: 27 Jul '10, 14:26

Seen: 3,170 times

Last updated: 20 Apr '11, 14:12

powered by OSQA