Modifying the ntpd deamon script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Modifying the ntpd deamon script
# 1  
Old 05-24-2009
Modifying the ntpd deamon script

I need to replace the line daemon ntpd $OPTIONS in the following script with daemon ntpd $OPTIONS 2>&1 > /var/log/ntpd.log &

what will happen?

The idea of replacing is to capture the output on the console into ntpd.log file.

Will this work?

----------------------------------------------------------------------------------------------------------







ilaf0006 24: cat ntpd
#!/bin/bash
#
# ntpd This shell script takes care of starting and stopping
# ntpd (NTPv4 daemon).
#
# chkconfig: - 58 74
# description: ntpd is the NTPv4 daemon. \
# The Network Time Protocol (NTP) is used to synchronize the time of \
# a computer client or server to another server or reference time source, \
# such as a radio or satellite receiver or modem.

# Source function library.
. /etc/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

if [ -f /etc/sysconfig/ntpd ];then
. /etc/sysconfig/ntpd
fi

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

ntpconf=/etc/ntp.conf
ntpstep=/etc/ntp/step-tickers

[ -x /usr/sbin/ntpd -a -f $ntpconf ] || exit 0

RETVAL=0
prog="ntpd"

# Is there a firewall running, and does it look like one we configured?
FWACTIVE=''
if [ -f /proc/net/ip_tables_names ]; then
if iptables -L -n 2>/dev/null | grep -q RH-Firewall-1-INPUT ; then
FWACTIVE=1
fi
fi

start() {
# get the servers from step-ticker
tickers=''
if [ -s "$ntpstep" ]; then
tickers=`/bin/sed -e 's/\#.*$//g' $ntpstep`
fi
timeservers=`/usr/bin/awk '$1=="peer"||$1=="server"{print $2}' $ntpconf`

# check for -x
OPTIND=0
dostep=''
while getopts ":aAbc:dD:f:gk:l:LmnNSmilie:P:qr:s:t:v:V:xU:T:" args $OPTIONS;
do
if [ "$args" = "x" ]; then
dostep='yes'
break
fi
done
OPTIND=0

# Open the firewall for ntp
if [ -n "$FWACTIVE" -a "$FIREWALL_MODS" != "no" ]; then
for server in `echo $tickers $timeservers | tr ' ' '\n' | sort -u`; do
echo -n $"$prog: Opening firewall for input from $server port 123"
iptables -I RH-Firewall-1-INPUT -m udp -p udp -s $server/32 \
--sport 123 -d 0/0 --dport 123 -j ACCEPT \
&& success || failure
echo
done
fi

if [ -z "$tickers" ]; then
tickers=$timeservers
fi

if [ -s "$ntpstep" -o -n "$dostep" ]; then
# Synchronize with servers if step-tickers exists
# or the -x option is used
echo -n $"$prog: Synchronizing with time server: "
/usr/sbin/ntpdate -s -b -p 8 $tickers
RETVAL=$?
[ $RETVAL -eq 0 ] && success || failure
echo
if [ $RETVAL -ne 0 ]; then
OPTIONS="$OPTIONS -g"
fi
else
# -g can replace the grep for time servers
# as it permits ntpd to violate its 1000s limit once.
OPTIONS="$OPTIONS -g"
fi
# Start daemons.
echo -n $"Starting $prog: "
daemon ntpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ntpd
return $RETVAL
}

stop() {
# Stop daemons.

# get the servers from step-ticker
tickers=''
if [ -s "$ntpstep" ]; then
tickers=`/bin/sed -e 's/\#.*$//g' $ntpstep`
fi
timeservers=`/usr/bin/awk '$1=="peer"||$1=="server"{print $2}' $ntpconf`

# Remove the firewall opening for ntp
if [ -n "$FWACTIVE" -a "$FIREWALL_MODS" != "no" ]; then
for server in `echo $tickers $timeservers | tr ' ' '\n' | sort -u`; do
echo -n $"$prog: Removing firewall opening for $server port 123"
iptables -D RH-Firewall-1-INPUT -m udp -p udp -s $server/32 --sport 123 -d 0/0 --dport 123 -j ACCEPT \
&& success || failure
echo
done
fi
echo -n $"Shutting down $prog: "
killproc ntpd
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ntpd
return $RETVAL
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status ntpd
RETVAL=$?
;;
restart|reload)
stop
start
RETVAL=$?
;;
condrestart)
if [ -f /var/lock/subsys/ntpd ]; then
stop
start
RETVAL=$?
fi
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
exit 1
esac

exit $RETVAL
# 2  
Old 05-25-2009
It won't really help, because ntpd already logs all output to syslog (unless you start it in no-fork mode, see -n). If you don't want to go through syslog, just use "-l logfile" in your options. I don't really see a need to change the script.

Adding & to the end isn't necessary unless one of your options is -n (don't fork).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need some help modifying script

I have a script that currently runs fine and I need to add or || (or) condition to the if statement and I'm not sure the exact syntax as it relates to the use of brackets. my current script starts like this: errLog="/usr/local/website-logs/error.log" apacheRestart="service httpd restart"... (3 Replies)
Discussion started by: jjj0923
3 Replies

2. Shell Programming and Scripting

awk script for modifying the file

I have the records in the format one row 0009714494919I MY010727408948010 NNNNNN N PUSAAR727408948010 R007YM08705 9602002 S 111+0360832-0937348 I want to get it int the format 0009714494919I MY010727408948010 NNNNNN N PUSAAR727408948010 R007YM08705 9602002 S ... (2 Replies)
Discussion started by: sonam273
2 Replies

3. Shell Programming and Scripting

Modifying the Restart Script

Hello, I have a shell script which calls for an existing script with appropriate parameters. It looks something like this. -------------------------------------------------------------------------- #!/bin/bash sh /root/ams_rc stop_shepherd > /dev/null sleep 30 sh /root/ams_rc... (9 Replies)
Discussion started by: Siddheshk
9 Replies

4. UNIX for Dummies Questions & Answers

Modifying a shell script without using an editor

Hi all, I really wan't to know that how to edit a shell script with out using an editor.. Is there any command? (4 Replies)
Discussion started by: buddhi
4 Replies

5. Shell Programming and Scripting

Modifying XML document with Unix Script

Hi, I have xml documents that I want to change a value in, I can do it using sed in a text document but not the xml document. I have read other posts that allow the change between tags but the part I wish to change is only a small part of data with the tags. e.g. <?xml version="1.0"... (2 Replies)
Discussion started by: heather.morton@
2 Replies

6. Shell Programming and Scripting

modifying file using script

Hi, I am new to shell programming, and want to know is it possible to change the contents of file using script? for example, if want to search 2 words and want to replace these words with 2 new words. Regards, Manoj (4 Replies)
Discussion started by: manoj.solaris
4 Replies

7. Shell Programming and Scripting

modifying perl script

Hi freinds I have a small problem I want u to help me in, I have a syslog server and configured it to send me email automatically, I get a small perl script to help me in, and tested it to send alerts to root and it worked successfully without any problems Now I want to send it outside, I... (4 Replies)
Discussion started by: reaky
4 Replies

8. Shell Programming and Scripting

Modifying a .ksh script

Hi users, I am on a beginner level and just joined this site. I have created a simple .ksh file in the following manner cat <<EOF >mfile #!/bin/ksh echo "hello world" EOF Request for some help with 2 cases 1. now i would like to add a second line after the first echo command... (4 Replies)
Discussion started by: corbusier
4 Replies

9. Shell Programming and Scripting

Help modifying script to loop through all folders

I have this script someone very kindly help me write last year which loops through all files in a folder and does a command. I need to modify it to loop through all sub-folders of a main folder and only perform the command on files modified after Jan 1st 2008. And I need the command to place the... (3 Replies)
Discussion started by: Fred Goldman
3 Replies

10. Shell Programming and Scripting

need help with understanding and modifying script

hi all, i am new to UNIX. this is my first time using Ubuntu. i need to do this for my fyp. i am using an artificial neural network model to predict the yield strength of steel. the shell script used to execute this model is as shown here: #Thomas Sourmail, Cambridge University /... (4 Replies)
Discussion started by: dakkorn
4 Replies
Login or Register to Ask a Question