nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Shell BIND NAMED Zone Creation Script

This is a discussion on Shell BIND NAMED Zone Creation Script within the Shell scripting forums, part of the Development/Scripting category; Hi Code: ######################################### #!/bin/bash -x NAMED_CONF_PATH="/etc/named.conf" gen="generic.hosts" domainame="" echo -n "Enter Domain Name : " read domainame if grep \"$domainame\" ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-02-2009, 11:04 PM
Senior Member
User
 
Join Date: Jul 2006
Posts: 145
Thanks: 0
Thanked 2 Times in 2 Posts
Rep Power: 4
asim.mcp is on a distinguished road
Default Shell BIND NAMED Zone Creation Script

Hi
Code:
#########################################
#!/bin/bash -x

NAMED_CONF_PATH="/etc/named.conf"
gen="generic.hosts"
domainame=""

echo -n "Enter Domain Name : "
read domainame

if  grep \"$domainame\" $NAMED_CONF_PATH > /dev/null ;
    then
    echo "Domain $domainame already exists, please try another domain"
    exit 1
fi

echo "zone  \"$domainame\" {" >> $NAMED_CONF_PATH
echo "       type master;  " >> $NAMED_CONF_PATH
echo "       file \"$gen\";" >> $NAMED_CONF_PATH
echo "};" >> $NAMED_CONF_PATH
echo "" >> $NAMED_CONF_PATH
###################################################
It works. But the problem is , if i don't enter a domain name it'll create a zone without any domain name.
I want it to be as if no domain name or no value is entered it should be exit else further performe, Can anyone help me into it???????

Thanks......

Last edited by nixcraft; 12-02-2009 at 11:11 PM.
Reply With Quote
  #2 (permalink)  
Old 12-02-2009, 11:15 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Replace
Code:
 read domainame
With:
Code:
 read domainame
[ "$domainame" != "" ] || ( echo "Usage: $0 domainname"; exit 1)
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 13-02-2009, 03:06 PM
Senior Member
User
 
Join Date: Jul 2006
Posts: 145
Thanks: 0
Thanked 2 Times in 2 Posts
Rep Power: 4
asim.mcp is on a distinguished road
Default

Thanks Dear,

But i've done this with the following...

It works. what i wanted.

######################################
#!/bin/bash
namepath="/etc/named.conf"
domainame=""
gen="generic.hosts"

clear
echo "e.g. 'example.com'"
echo -n "Enter Domain Name : "
read domainame

if [ "$domainame" = "" ]
then
clear
echo "You 've not entered any Domain Name, try again"
exit 1
else
if grep \"$domainame\" "$namepath" > /dev/null ; then
clear
echo "Domain $domainame already exists, please try another domain"
exit 1
fi
fi

echo "zone \"$domainame\" {" >> $namepath
echo " type master; " >> $namepath
echo " file \"$gen\";" >> $namepath
echo "};" >> $namepath
echo "" >> $namepath
clear
echo "Zone Record for the Domain '$domainame' is Successfully created"
################################################## ####
Reply With Quote
  #4 (permalink)  
Old 13-02-2009, 04:39 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Yes, it works both ways but my code is short.

Short code == faster execution

Heh
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #5 (permalink)  
Old 13-02-2009, 04:51 PM
Senior Member
User
 
Join Date: Jul 2006
Posts: 145
Thanks: 0
Thanked 2 Times in 2 Posts
Rep Power: 4
asim.mcp is on a distinguished road
Default

Yes buddy you are right... well thanks for your reply..
Reply With Quote
Reply

Tags
bind , bind shell script , named , named shell script , zone creation shell script


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
How to Delete a file on 46 th day from the day of creation knvpavan Shell scripting 6 12-02-2009 12:07 AM
getting errors from named.conf in rhel5 ashu.wifi CentOS / RHEL / Fedora 2 17-09-2008 02:02 PM
Binary Conversion Of Shell Script (shell script compiler) chandanperl Shell scripting 3 29-07-2008 10:22 AM
Linux Change the time zone configuration after installation raj Linux software 1 17-07-2006 02:11 AM
mysql account creation Linux software 1 28-01-2006 11:17 AM


All times are GMT +5.5. The time now is 02:23 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

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