Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 07 Jan 2012 15:37:49 +0200
From:      Kaya Saman <kayasaman@gmail.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: Having problems running shell script from crontab
Message-ID:  <4F084AAD.3050301@gmail.com>
In-Reply-To: <20120107132234.31d04a1c@gumby.homeunix.com>
References:  <4F0838DF.40006@gmail.com> <20120107132234.31d04a1c@gumby.homeunix.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <jail> tcsh

which gets me in as root. Crontab is being run as root so paths should 
be the same no?


Hmm..... am puzzled!


Kaya



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4F084AAD.3050301>