0

Trying to delete a zone file from a name server (remote) from a local machine (connecting to the remote server with a key pairing).

Script on the name server is below (remzone) which is executable.

#!/bin/bash
sed -i '/$1/,+4d' /etc/named.conf
rm -f /var/named/slaves/$1.db
rndc reload
echo "$1"

The local command I am running is.....

ssh root@server '~/remzone domain.com'

When I run the command locally, the following output is provided.

me@Main:~$ ssh root@server '~/remzone domain.com'
server reload successful
domain.com

When executing the command locally, the domain.com.db is removed from /var/named but it does not remove the matching line (+4 lines) from /etc/named.conf.

Zone    "domain.com" IN {
        type slave;
        masters {XXX.XXX.XXX.XXX;};
        file "slaves/domain.com.db";
};

When I run sed -i '/domain.com/,+4d' /etc/named.conf on the nameserver directly, it deletes the zone file correctly from the /etc/named.conf file.

Any Ideas?

Unisom
  • 9
  • Your shellscript has incorrect quoting on two lines. Whenever you have a shell script error, a good first step is to cut and paste your code into shellcheck.net and correct the errors (important) and warnings (might be important) that it identifies. If you have trouble understanding its messages, then come here and ask. – John1024 Aug 13 '20 at 03:58
  • 1
    Changed the script (remzone) on the remote server from sed -i '/$1/,+4d' /etc/named.conf to sed -i "/$1/,+4d" /etc/named.conf AND rm -f /var/named/slaves/$1.db to rm -f /var/named/slaves/"$1".db. That corrected the issue. @John1024 Thank you very much for the assistance and https://www.shellcheck.net. I did not know that site was around. – Unisom Aug 13 '20 at 04:26

0 Answers0