System Administration
Showing results for 
Search instead for 
Did you mean: 

script to start nis.server hung

tom quach_1
Super Advisor

script to start nis.server hung

i've created a script to stop and start nis.server below.


NUM=`ps -ef |grep ypserv|wc|awk '{print $1}'`

if [ $NUM -lt 0 ]
exit 0
/sbin/init.d/nis.server stop
/sbin/init.d/nis.server start
mailx -r root@`uname -n` -s "Starting nis.server on `uname -n` `date`" exit 1

When running this script manually,
it's alway hung at this location. but if i run from command line this line
#/sbin/init.d/nis.server stop
it's always work.

Would you Please suggest a work around for this.

stopping rpc.yppasswd
stopping rpc.ypupdated
stopping ypserv
stopping ypxfrd
#stopping keyserv <---hung right here

Thanks in advance.
Honored Contributor

Re: script to start nis.server hung

Ok, so what is this? "test:[root]:[TWO_TASK=xxx]:/util/run"?

Are you running this out of some kind of scheduler / monitor package?

Your script is Add "set -x" to it and run it from the command line and log the output.

Make sure you don't have issues with "@" being the "kill" character.

FUll path to mailx?

Line wrap in the mailx command line or is it continued with "\"?

I don't haves access to the nis.server script, does it even look at "ketsvr"?
Why "exit 1"?
Bill Hassell
Honored Contributor

Re: script to start nis.server hung

> NUM=`ps -ef |grep ypserv|wc|awk '{print $1}'`

This is a very unreliable way to locate a program by name. grep and ps are a very unstable combination because grep does not look where you want it too. If you run ps -ef|grep ypserv several times, you'll find that grep finds grep -- giving you a false positive. The code is much more reliable using the -C option in ps, like this:

UNIX95=1 ps -C ypserv > /dev/null 2>&1
[ $# -ne 0 ] && exit 0

To explain: UNIX95=1 sets a temporary variable for ps to use extra options, namely -C. Always place it on the same line as ps because setting UNIX95 for the environment will cause other unexpected changes. The return code from ps will be zero when one or more processes are found, non-zero when nothing is found. See the man page for ps for a lot of very useful values.

Use this technique to find processes by name and dump ps+grep.

Bill Hassell, sysadmin