Fail to run init-script from crontab


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Fail to run init-script from crontab
# 1  
Old 09-12-2005
Data Fail to run init-script from crontab

I have written a "simple" shell-script (BASH) to monitor the logs of our Resin-applicationserver. Whenever Resin runs out of available heap-space, the script then tries to restart the Resin-server.

My problem is that my "autopilot"-script fails when it's run from crontab.

Here's what the script does:

1. Check available heap-space. If heap-space < 15%, then restart server.

2. I created a function to stop the server, which is called next in this event.
Code:
func_emma_stop()
{
        if [ $test -eq 0 ]; then
                /etc/init.d/resin stop
        else
                func_eventlog "Resin should now be stopped!"
        fi
        if [ $debug -eq 1 ]; then
                func_eventlog "emma_stop was called, result=Stopping!"
        fi
}

3. Next I verify if all processes are stopped. I cannot use the command "/etc/init.d/resin restart" because the server will sometimes take too long to stop (handling user sessions) and I cannot depend on the sleep-command in the init-script.

4. Next I try to start the server using this function:
Code:
func_emma_start()
{
        if [ $test -eq 0 ]; then
                /etc/init.d/resin start
        else
                func_eventlog "Resin should now be started!"
        fi
        if [ $debug -eq 1 ]; then
                func_eventlog "emma_start was called, result=Starting!"
        fi
}

5.Then again check for successful start. Retry when failed or exit when done.
  • Now, when run from commandline, this script works great.
  • When I execute the /etc/init.d/resin stop/start from commandline, it also works great.
  • But... when run from crontab, every 5 minutes, it can stop the server, but fails to start it again.

When run from crontab, it tries to execute "/etc/init.d/resin start" over and over again, without result. I know this, because I made the init-script mail me when it's called. There's no output at all, no errors in logging, nothing... Smilie

Do I need a special way to call the init-script? (Instead of just executing it)

One more problem for me is that we just acquired the company who runs this application and I am its admin. However, I only have a production-environment and cannot "experiment" too much.

Any help/hints would be much appreciated. Smilie
# 2  
Old 09-12-2005
Also, I run this from root's crontab. Does this mean I automatically use root's environment-settings?

crontab-entry below:
Code:
*/5 7-18 * * 1-5 /home/beheer/scripts/logchecker-autopilot.sh 1>/dev/null 2>/dev/null

# 3  
Old 09-13-2005
# 4  
Old 09-14-2005
Change the script sh to csh & check
# 5  
Old 09-14-2005
It works!

I finally found out why things weren't working... I ran the env-command from crontab and did the same for root and found out that crontab's path was only /bin;/usr/bin. The init-script "inherited" these environmentsettings and couldn't find the Debian /sbin/start-stop-daemon. From there on, it was simple... Smilie

Thanks guys!
# 6  
Old 09-14-2005
Quote:
Originally Posted by indo1144
I finally found out why things weren't working... I ran the env-command from crontab and did the same for root and found out that crontab's path was only /bin;/usr/bin. The init-script "inherited" these environmentsettings and couldn't find the Debian /sbin/start-stop-daemon. From there on, it was simple... Smilie

Thanks guys!
We use SUSE SLES Linux at my office a great deal and I run into this issue a great deal. One of the things I find that helps is doing a sudo -c to run commands from crontab. It seems to apply the real user environment to the cron shell. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script fails to run properly when run from CRONTAB

Hello all, I'm trying to write a script to gather and send data and it works just fine at the bash command line, but when executing from CRON, it does not run properly. My scripting skills are pretty limited and there's probably a better way, but as I said it works at the command line, but... (12 Replies)
Discussion started by: rusman
12 Replies

2. Shell Programming and Scripting

Cannot get this bash/expect script to run under a crontab

#!/bin/bash # # RAP configuration script # # Usage: ./rap.sh # # Requires: expect, tcl # # Script expects to find a file called rap.csv located in the same directory as the script. If the file is placed # in a different directory, modify the custom entries section to specify the absolute... (8 Replies)
Discussion started by: mrkool
8 Replies

3. Red Hat

init-script failing because of /etc/rc.d/init.d/functions

I encountered a problem on one of our database servers. OS: CentOS 5.5 final Kernel: 2.6.18-238.5.1.el5.028stab085.2 (OpenVZ kernel) We wrote some DB-Start/Stop-scripts ("/db2/admin/scripts_dba/start_services.ksh" and ".../stop_services.ksh") to start the database instances. (Database... (1 Reply)
Discussion started by: bakunin
1 Replies

4. Shell Programming and Scripting

run script through crontab using ksh

hi i have a script called test.sh. the content is ls >> crontest.txt. if i run manually it's giving output.but if i scheduled in crontab it's not giving output. crontab entry: 02 * * * * /sms5/SMSHOME/eds_sh/test.sh >> /sms5/SMSHOME/eds_sh/testfile/logfile 2>&1 I am using ksh.is there... (2 Replies)
Discussion started by: muraliinfy04
2 Replies

5. Shell Programming and Scripting

crontab fails to run script

OS is Ubuntu 8.04.3. When I run the command: /usr/bin/syslogMailer < /etc/syslog.pipes/criticalMessagesFrom a bash shell it works and i receive an email as per the script however when run from crontab it does not work. Can anyone explain why and how to fix it? /usr/bin/syslogMailer... (4 Replies)
Discussion started by: jelloir
4 Replies

6. Shell Programming and Scripting

Script not running properly when run from Crontab

Hi I am a novice Linux/Perl user and am struggling to overcome what I am sure is a simple problem. I am using a perl program to create a shell script daily containing between 10 and 30 "at -f" commands for the same day. Then I change the file attributes to allow the file to be executed. When... (2 Replies)
Discussion started by: simoncjones
2 Replies

7. Shell Programming and Scripting

run script 1 minute interval without CronTab

I am using Solaris 9. I wish to run my script every 1 minute inteval. Though i can run it using below entry in crontab. * * * * /export/home/username/script/file_exist_&_run.sh in short above script will check whether a specific file exist in a directory. If it found it will inovke another... (10 Replies)
Discussion started by: thepurple
10 Replies

8. Shell Programming and Scripting

How do i run a shell script without crontab.

Hi Folks, Could you please suggest me how to run a shell script on a solaris env without using crontab. I am actually trying to write a shell script which will grep "WORD" in the logfile andd sends a email.Thanks in advance. Thanks Sandeep. (3 Replies)
Discussion started by: sandeep anand
3 Replies

9. Shell Programming and Scripting

recurring run of sh script in crontab

Hello gurus. I have a problem: my crontab -e is looks like this: ORACLE_SID=bla-bla * 21 * * * (sqlplus hotback/hotback @/oracle/backups/bla-bla/scripts/hotback/daily_hotback.sql) 0 19 * * * /oracle/backups/dev10g/scripts/exports/daily_exports.sh 0 1 * * *... (4 Replies)
Discussion started by: MarGur
4 Replies

10. AIX

crontab displays power fail

Hi, My system has added an entry to the cron: --> crontab -l 0 00,12 * * * wall%rc.powerfail:2::WARNING!!! The system is now operating with a power problem. This message will be walled every 12 hours. Remove this crontab entry after the problem is resolved. I have had an issue... (8 Replies)
Discussion started by: chlawren
8 Replies
Login or Register to Ask a Question