Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Need help on tomcat restart via cronjob

by SriniK (Beadle)
on Oct 30, 2013 at 09:46 UTC ( [id://1060307]=perlquestion: print w/replies, xml ) Need Help??

SriniK has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I'm using perl script to restart the tomcat, the command which i am using given below.
$tomcat_status=`sudo /****/***/bin/catalina.sh start`; print "$date: $tomcat_status\n";
Output
Wed Oct 30 05:35:14 EDT 2013: Using CATALINA_BASE: /****/**** Using CATALINA_HOME: /****/**** Using CATALINA_TMPDIR: /****/****/temp Using JRE_HOME: /usr Using CLASSPATH: /****/****/bin/bootstrap.jar:/****/****/bin/tom +cat-juli.jar
Everything working fine while running via putty. But when via cron it not tomcat not restarted and there is no output as well.
I have imported the all bash environmental variables to the perl program but still its not working
Need your help on this.

Thanks
SRI

Replies are listed 'Best First'.
Re: Need help on tomcat restart via cronjob
by derby (Abbot) on Oct 30, 2013 at 10:27 UTC

    Probably not a perl problem but either a sudo permission problem or an environment variable problem.

    • What account is kicking off the crontab? A users or roots? If a user, does that user have sudo permissions -- if it's roots crontab, you don't need to sudo at all.
    • There may be environment variables (JAVA_HOME and PATH come to mind) that are set when you kick off from the command line but are not present in the cron environment. Tomcat (catalina.sh) will invoke the setenv.sh script in order to set environment variables. By default that script is either blank or not there. Just create it and and your needed env settings there.

    -derby
      I am running the script from root user the below are the evs from the script
      HOME : /root CVS_RSH : ssh DISPLAY : :99 LESSOPEN : |/usr/bin/lesspipe.sh MAIL : /var/spool/mail/root PWD : /root LANG : en_US.UTF-8 USER : root G_BROKEN_F: 1 LOGNAME : root SHLVL : 2 HOSTNAME : ***.****.****.** JAVA : /usr/bin/ _ : /bin/env PATH : /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/b +in:/root/bin SHELL : /bin/sh HISTSIZE : 1000 HISTCONTRO: ignoredups
Re: Need help on tomcat restart via cronjob
by McA (Priest) on Oct 30, 2013 at 10:21 UTC

    Hi,

    IMHO not really a Perl related question. It's more one of the recurring questions, why a script is not working under cron when it is working in a terminal. And this has to do almost always with environment variables not being set properly while running under cron.

    IMHO the simplest solution for that is calling the job in cron this way:

    bash -l -c "perl $path_to_perlscript/someperlscript.pl arg1 arg2"

    UPDATE: This shall show the idea behind. It depends on the shell used.

    Best regards
    McA

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1060307]
Approved by marto
Front-paged by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-20 11:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found