DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   (View Single Post)  
Old 6th June 2008
splooge splooge is offline
New User
 
Join Date: May 2008
Posts: 5
Thanked 0 Times in 0 Posts
Default Appending to file on remote host via SSH

Hey guys! I'm playing around with scripting for (basically) my first time. I found out most of what I needed through examples I found on google and have finished with about the first three-fourths of the script. Essentially, I am creating a script that makes my life easier when adding domains to my DNS servers. In one of our DNS farms we have 5 servers (1 master, not public facing, and 4 slaves which *are* public facing). In any case, creating the initial zone file and then modifying 5 instances of named.conf can get quite tedious when you're adding almost a new domain every day, so I'm trying to come up with a solution.

The script, when complete, will do this:

1) Create an initial zone file in /etc/namedb/master/
2) Add the zone to named.conf
3) Reload named, to read in the new named.conf
4) via SSH, append the new zone to named.conf on the slaves
5) via rndc, reload the slaves remotely

This part all works EXCEPT for #4 above:
Code:
if [ -z "$1" ] || [ -z "$2" ]
then
        echo "Proper usage of this script is `basename $0` [domain-name] [IP address]"
        exit
fi

#Let's do the zone file ...
echo "Creating initial zone file ..."

echo "\$TTL 300
$1.                     IN SOA  ns1.pwned.com. hostmaster.pwned.com. (
                                2008060401 ; serial
                                1H         ; refresh
                                10M        ; retry
                                1D         ; expire
                                1D         ; minimum
                                )

                        NS      ns1.pwned.com.
                        NS      ns2.pwned.com.

                        A       $2
www                     CNAME   @
" > /etc/namedb/master/db.$1

echo "Changing ownership on db.$1 ..."
chown bind:bind /etc/namedb/master/db.$1

# Let's update named.conf ...
echo "Updating named.conf ..."

echo zone \"$1\"" {
        type master;
        file \"master/db.$1\";
};
" >> /etc/namedb/named.conf

# Reload named for changes to take effect ...
echo "Reloading named ..."

rndc reload
What I *can't* get to work is appending to file on a remote host via SSH. I get errors at the curly braces and the $1 variable doesn't get carried over to the remote box. Here's basically what I am trying that is failing: (Note: ns1 is FreeBSD, ns2 is Gentoo)

Code:
ssh ns2 echo "zone \"test.com\" {
	type slave;
	file \"sec/db.test.com\";
	masters { 72.26.x.x; };
};
" >> /etc/namedb/named.conf
These are the error messages I get:
Code:
bash: line 1: type: slave: not found
bash: -c: line 3: syntax error near unexpected token `}'
bash: -c: line 3: `	masters { 72.26.x.x; };
Can anyone suggest the proper code to append multiple lines to a file on a remote machine via SSH that will ALSO carry the $1 variable over to the remote machine?

Thanks. I hope I was clear enough.

Last edited by splooge; 7th June 2008 at 02:37 AM.
Reply With Quote
 

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP read file contents - Maximum file size cksraj Programming 1 21st September 2009 11:38 AM
ssh/rdesktop into host behind NAT JMJ_coder General software and network 18 13th January 2009 08:19 PM
Print on remote WinXP from web host drhowarddrfine General software and network 5 13th October 2008 05:41 PM
Remote Access to File Server Oko OpenBSD Security 7 23rd June 2008 05:17 PM
Changing IP to host www, mail and etc in FreeBSSD neubie FreeBSD General 5 19th June 2008 07:34 AM


All times are GMT. The time now is 08:12 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick