Sunday, August 30, 2015

Add user to sudoers

Add user to sudoers

Create user: username
useradd username

Add to sudoers

vi /etc/sudoers
With content
username      ALL=(ALL)       NOPASSWD: ALL


SSH Log in with user: username and switch to user: root
sudo su


It will not ask for the password.

Thursday, August 27, 2015

Scripts - Add - DNS Record

Scripts - Add - DNS Record


What : This script is going to add the CNAME record map to srv001, and add under the record srv001
HowTo : ./add-cname-record.sh recordname

Create a file name: add-cname-record.sh and the following content:

#!/bin/bash
USAGE="Usage: $0 recordname"
if (! test $1)
then
 echo $USAGE
 exit 1
fi

echo "Checking is the domain: $1.vannakk.net existed or not yet."
FILE=/etc/bind/forward.vannakk.net.zone
grep -w "$1" $FILE >/dev/null
if [ $? -eq 0 ]
then
   echo "Domain: $1.vannakk.net already existed "
        exit 1
else
   echo "Domain: $1.vannakk.net not yet existed. So this domain will be add."
sed -i '/^srv001/a \'$1'         IN      CNAME   srv001.vannakk.net.' $FILE
fi

echo "Updating Serial..."
SERIAL=$(awk '/serial/{print $1}' $FILE)
sed -i "/serial/s/$SERIAL/$(expr $SERIAL + 1)/" $FILE

echo "Reloading service named"
service bind9 reload
echo "Domain: $1.vannakk.net is added."