From owner-freebsd-questions@FreeBSD.ORG Sat Jan 7 12:50:47 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 34D58106566C for ; Sat, 7 Jan 2012 12:50:47 +0000 (UTC) (envelope-from kayasaman@gmail.com) Received: from mail-we0-f182.google.com (mail-we0-f182.google.com [74.125.82.182]) by mx1.freebsd.org (Postfix) with ESMTP id BE1328FC12 for ; Sat, 7 Jan 2012 12:50:46 +0000 (UTC) Received: by werb13 with SMTP id b13so2479843wer.13 for ; Sat, 07 Jan 2012 04:50:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=jgjAwFEDvPIQffDiD8/3TC6KRDu3Heus8AM1QgYtHL0=; b=V3DcPw1+cL6Wgd7e82eNbRzbtDP+6Jwly2kVXXIZnV6fv5O8P4HTKLtowxK1Apqx/1 Ekz2VlyMmcpp0PLLUdvDybA4OhazfTRoKl9nCfF/0jEf76GVypix5Wly2PCXpcVo9RDl Xi41VlWhr3P0YLCK/SCQeTOTNbJvmmLNqBtKw= Received: by 10.216.137.195 with SMTP id y45mr608327wei.45.1325938924600; Sat, 07 Jan 2012 04:22:04 -0800 (PST) Received: from Hp2230s.localhost (81-178-2-118.dsl.pipex.com. [81.178.2.118]) by mx.google.com with ESMTPS id m13sm71772311wbh.0.2012.01.07.04.22.02 (version=SSLv3 cipher=OTHER); Sat, 07 Jan 2012 04:22:03 -0800 (PST) Message-ID: <4F0838DF.40006@gmail.com> Date: Sat, 07 Jan 2012 14:21:51 +0200 From: Kaya Saman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111115 Thunderbird/8.0 MIME-Version: 1.0 To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Having problems running shell script from crontab X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Jan 2012 12:50:47 -0000 Hi, I wrote a shell script to detect if the port of tomcat was in use or not then restart if the port wasn't online; due to tomcat segfaulting as my system hasn't got enough memory for it. This is the shell script: #!/usr/local/bin/bash ntstat=`netstat -ap tcp | grep 8180 | sed -n '1p'` port="8180" #echo $ntstat #echo $port if [[ $ntstat =~ $port ]]; then echo "Output of Netstat command $ntstat port number $port" > /root/java_restart/java_restart.log; else wait 60; /usr/local/etc/rc.d/tomcat6 restart; fi Here in /var/log/cron - it can be seen that the script has been executed: Jan 7 10:30:00 wiki /usr/sbin/cron[19509]: (root) CMD (/root/java_restart/java_restart.sh) Jan 7 11:00:00 wiki /usr/sbin/cron[20418]: (root) CMD (/root/java_restart/java_restart.sh) Jan 7 11:30:00 wiki /usr/sbin/cron[21356]: (root) CMD (/root/java_restart/java_restart.sh) Jan 7 12:00:00 wiki /usr/sbin/cron[22455]: (root) CMD (/root/java_restart/java_restart.sh) The strange thing is that if I run this script manually /root/java_restart/java_restart.sh it works fine and does what it's supposed to do. Cron however seems to execute the IF statement but not get as far as else??? - it seems as tomcat doesn't restart. Here is my little log file that tells the port is active: -rw-r--r-- 1 root wheel 116 Jan 7 11:30 java_restart.log If I stop tomcat just before the xx:00 or xx:30 time designations tomcat will not be restarted by the script and I don't understand why? This is the crontab: 0,30 * * * * /root/java_restart/java_restart.sh which is being run as root user. Can anyone suggest anything that might be a possible cause for tomcat not getting restarted automatically when the proper conditions are met? Regards, Kaya