Hello Joachim, On Mon, 10 Oct 2005 10:43:57 -0700 (PDT) Joachim Smit <[EMAIL PROTECTED]> wrote:
> Because some naughty boys try to get in one of my > clients' Debian-server a couple of hundred times a day > I decided to shut down sshd when I don't need. With a > simple mechanisme I can start sshd from distance > whenever I want. > > Just in case I might forget to close it when I'm > ready, I run the following script 4 times a day: > > ================ > > #!/bin/sh > > DATE="/bin/date" > DATUM=$($DATE +"%Y-%m-%d-%H:%M") > SUBJECT="HOL/"$DATUM > > AANTAL=`ps -ef | /bin/grep '/usr/sbin/sshd' | > /usr/bin/wc -l` > > if [ $AANTAL -ne 0 ] ; then > > /etc/init.d/ssh stop > /usr/bin/mail [EMAIL PROTECTED] -s $SUBJECT < > /usr/local/sbin/txt/uittekst > > fi > > ========================== > > The strange thing is that when I run the script > interactive, it doesn't try to shut down sshd when > it's not active. > > But when I call the script from crontab it ALWAYS > sends me an email, in other words, $AANTAL is always > greater than 0. When I echo the value of $AANTAL I see > that running from crontab it is always 1, running the > script interactive it is always 0 (if sshd is not > active) Use pgrep sshd instead of your script line, see ps -ef | /bin/grep '/usr/sbin/sshd' root 4671 1 0 17:50 ? 00:00:00 /usr/sbin/sshd joerg 23168 5365 0 20:01 pts/0 00:00:00 /bin/grep /usr/sbin/sshd Jörg -- Jörg Schütter http://www.schuetter.org/joerg [EMAIL PROTECTED] http://www.lug-untermain.de/