Having problems running shell script from crontab

Kaya Saman kayasaman at gmail.com
Sat Jan 7 13:38:04 UTC 2012


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 at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at 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


More information about the freebsd-questions mailing list