From owner-freebsd-questions Fri Jan 17 04:23:56 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id EAA26672 for questions-outgoing; Fri, 17 Jan 1997 04:23:56 -0800 (PST) Received: from mail.EUnet.hu (www.eunet.hu [193.225.28.100]) by freefall.freebsd.org (8.8.4/8.8.4) with ESMTP id EAA26654 for ; Fri, 17 Jan 1997 04:23:49 -0800 (PST) Received: by mail.EUnet.hu, id NAA01378; Fri, 17 Jan 1997 13:23:42 +0100 Received: (from zgabor@localhost) by CoDe.hu (8.7.5/8.7.3) id NAA00500 for freebsd-questions@freebsd.org; Fri, 17 Jan 1997 13:17:23 +0100 (MET) From: Zahemszky Gabor Message-Id: <199701171217.NAA00500@CoDe.hu> Subject: Re: Crontab for killing and restarting named To: freebsd-questions@freebsd.org (FreeBSD questions) Date: Fri, 17 Jan 1997 13:17:23 +0100 (MET) In-Reply-To: <199701170922.BAA09807@connectnet1.connectnet.com> from That Doug Guy at "Jan 17, 97 01:21:26 am" X-Mailer: ELM [version 2.4ME+ PL11 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > Ok, this is driving me nutty. I need to kill named once a day, and then > restart it. First I tried a command line to do this in the crontab, but I couldn't get > that to work, so I decided to use a script. Here is the script that I ended up with: > > #!/bin/sh > PID=`/bin/ps ax | /usr/bin/grep named | /usr/bin/grep -v grep | /usr/bin/awk > '{print $1}'` > /bin/kill -9 ${PID} > /bin/sleep 5 > /usr/sbin/named > > The only problem is, it doesn't work properly. When I run it from the command Yes, because it's name contains ``named'', too, and awk find it. 1) I found it in AEllen Frisch's Essential System Administration: instead of: .... | grep foo | grep -v grep it would be good: .... | grep '[f]oo' It's cheaper, because it uses only 1 grep process, and 1 pipe, not two of them. (And if you use grep in the original instead of fgrep, the time and memory are ~ same.) 2) Your problem has a much cheaper solution: kill -9 `cat /var/run/named.pid` in your script, or use the systems /usr/sbin/named.restart or /usr/sbin/ndc restart scripts, designed for this problem. Bye, Gabor