1834130 Members
2485 Online
110064 Solutions
New Discussion

Script Needed

 
SOLVED
Go to solution
M.sureshkumar
Regular Advisor

Script Needed

Hi All,
I need scrips for NTP server side and NTP clien side.I have attached NTP server side procdeure and NTP client side procedure.This is very urgent script.please do the needful.

Configuring an NTP Server :

The steps to configure a system to be an NTP Server are:

1. Edit the /etc/rc.config.d/netdaemons
Eg: lcscore1(10.3.10.14)

export NTPDATE_SERVER= lcscore1
export XNTPD=1
export XNTPD_ARGS= "-c /etc/ntp.conf"

2. Edit the /etc/ntp.conf

server lcscore1 version 1 prefer
fudge 10.3.10.14 stratum 10

3. Start the xntpd daemon manually by executing the following command:

sbin/init.d/xntpd start

Configuring an NTP Client

The complete, step-by-step procedure for configuring an NTP client is:

1. Edit the /etc/rc.config.d/netdaemons

export NTPDATE_SERVER= lcscore1
export XNTPD=1
export XNTPD_ARGS= "-c /etc/ntp.conf"

2. Edit the /etc/ntp.conf

fudge 10.3.10.14 stratum 10
server lcscore1 version 1 prefer

3. Start the xntpd daemon manually by executing the following command:

/sbin/init.d/xntpd start

Thanks&Regards,
Sureshkumar.





1 REPLY 1
Muthukumar_5
Honored Contributor
Solution

Re: Script Needed

You can use the script as,

#!/bin/ksh
#server.ksh
NTPSERVER="lcscore1";
NTPIP="10.3.10.14"
FLAG=0;

# 1
while read line;
do

echo $line | grep -q 'export NTPDATE_SERVER'
if [[ $? -eq 0 ]]
then
echo "export NTPDATE_SERVER=$NTPSERVER"
FLAG=1
fi

echo $line | grep -q 'export XNTPD'
if [[ $? -eq 0 ]]
then
echo "export XNTPD=1"
FLAG=1
fi

echo $line | grep -q 'export XNTPD_ARGS'
if [[ $? -eq 0 ]]
then
echo "export XNTPD_ARGS=\"-c /etc/ntp.conf\""
FLAG=1
fi

if [[ $FLAG -eq 0 ]]
then
echo $line
fi

FLAG=0;

done < /etc/rc.config.d/netdaemons /tmp/netdaemons

mv /tmp/netdaemons /etc/rc.config.d/netdaemons

# 2
grep -Eq '^server|^fudge' /etc/ntp.conf
if [[ $? -eq 0 ]]
then
sed -i -e '/^server/d;/^fudge/d' /etc/ntp.conf
fi

echo "server $NTPSERVER version 1 prefer" >> /etc/ntp.conf
echo "fudge $NTPIP stratum 10" >> /etc/ntp.conf

# 3
/sbin/init.d/xntpd start

exit 0
##
===================================

#!/bin/ksh
#client.ksh
NTPSERVER="lcscore1";
NTPIP="10.3.10.14"
FLAG=0;

# 1
while read line;
do

echo $line | grep -q 'export NTPDATE_SERVER'
if [[ $? -eq 0 ]]
then
echo "export NTPDATE_SERVER=$NTPSERVER"
FLAG=1
fi

echo $line | grep -q 'export XNTPD'
if [[ $? -eq 0 ]]
then
echo "export XNTPD=1"
FLAG=1
fi

echo $line | grep -q 'export XNTPD_ARGS'
if [[ $? -eq 0 ]]
then
echo "export XNTPD_ARGS=\"-c /etc/ntp.conf\""
FLAG=1
fi

if [[ $FLAG -eq 0 ]]
then
echo $line
fi

FLAG=0;

done < /etc/rc.config.d/netdaemons /tmp/netdaemons

mv /tmp/netdaemons /etc/rc.config.d/netdaemons

# 2
grep -Eq '^server|^fudge' /etc/ntp.conf
if [[ $? -eq 0 ]]
then
sed -i -e '/^server/d;/^fudge/d' /etc/ntp.conf
fi

echo "fudge $NTPIP stratum 10" >> /etc/ntp.conf
echo "server $NTPSERVER version 1 prefer" >> /etc/ntp.conf

# 3
/sbin/init.d/xntpd start

exit 0
##

It will work.
Easy to suggest when don't know about the problem!