From owner-freebsd-questions@FreeBSD.ORG Sat Jan 7 13:38:04 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 45602106566B for ; Sat, 7 Jan 2012 13:38:04 +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 C81DA8FC12 for ; Sat, 7 Jan 2012 13:38:03 +0000 (UTC) Received: by werb13 with SMTP id b13so2502743wer.13 for ; Sat, 07 Jan 2012 05:38:02 -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:references :in-reply-to:content-type:content-transfer-encoding; bh=cekFZHUxf9rZbBznu2ac7+LkC6swQBburWXQ9NlkOf8=; b=cVrxpk8T+WlmiiWxoXV9qkO6o2jTLhej6dkpDYCCCm3Bucg9wCLz+wbGHymT9wu5gs nBR3FMijLyTLTSy/pE0xu1d3d/U2dCyJfRJgiByFZ7o3Dwh0uvyOgpw20EcBaAbGm1bZ SvJbFjZuzdK3i63MbiTNbIcxAcYOxXzxFWehQ= Received: by 10.216.136.73 with SMTP id v51mr725309wei.5.1325943482639; Sat, 07 Jan 2012 05:38:02 -0800 (PST) Received: from Hp2230s.localhost (81-178-2-118.dsl.pipex.com. [81.178.2.118]) by mx.google.com with ESMTPS id 28sm71969004wby.3.2012.01.07.05.38.00 (version=SSLv3 cipher=OTHER); Sat, 07 Jan 2012 05:38:01 -0800 (PST) Message-ID: <4F084AAD.3050301@gmail.com> Date: Sat, 07 Jan 2012 15:37:49 +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 References: <4F0838DF.40006@gmail.com> <20120107132234.31d04a1c@gumby.homeunix.com> In-Reply-To: <20120107132234.31d04a1c@gumby.homeunix.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: 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 13:38:04 -0000 On 01/07/2012 03:22 PM, RW wrote: > On Sat, 07 Jan 2012 14:21:51 +0200 > Kaya Saman wrote: >> 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. > The commonest reason for scripts that that work from a terminal > failing under cron is that the environment isn't set-up correctly. > Usually it's PATH that's missing or incomplete. > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" Would it be possible to elaborate? I just fixed my script by altering some parts to Yuri's suggestions: #!/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 sleep 60; /usr/local/etc/rc.d/tomcat6 restart; fi with crontab now looking like so: 0,30 * * * * /usr/local/bin/bash /root/java_restart/java_restart.sh Sleep works fine but tomcat still isn't getting restarted...... In terms of paths this is what I'm doing: I'm in a FreeBSD jail logged in by - #jexec tcsh which gets me in as root. Crontab is being run as root so paths should be the same no? Hmm..... am puzzled! Kaya