Operating System - HP-UX
1833589 Members
3689 Online
110061 Solutions
New Discussion

shell file doesn't run with crontab

 
SOLVED
Go to solution
Hoang Chi Cong_1
Honored Contributor

shell file doesn't run with crontab

Hi all

Has anyone faced with this trouble:

I have create a scheduled task in crontab:
00 01 * * * sh /script/perfcheck/checkperf.sh

This shell file will kill and old process and will execute a new process for monitoring system performance.
And the content of that sell file:
########################
ps -ef|grep glance | grep adviser |cut -c9-19 | while read name
do kill -9 $name
done
sh /script/perfcheck/perflog.sh
#########################

The perflog.sh file content:
##########################
GetDate=`date +"%Y%m%d"`
LOG_NM=/script/perfcheck/logfile/log.$GetDate
nohup glance -j 60 -adviser_only -syntax /script/perfcheck/advfile >>$LOG_NM &
##########################
The advfile file:

##########################
print GBL_STATTIME, GBL_CPU_TOTAL_UTIL, GBL_DISK_UTIL_PEAK, GBL_MEM_UTIL, GBL_SWAP_SPACE_UTIL, GBL_DISK_SUBSYSTEM_QUEUE
##########################


The strange thing is:

It killed successful the old process but it doesn't run new process. That means the command:
sh /script/perfcheck/perflog.sh doens't run but the logfile still created (it just create the logfile only!)

Thanks in advanced!
Looking for a special chance.......
4 REPLIES 4
Ninad_1
Honored Contributor

Re: shell file doesn't run with crontab

Can you try giving the full path for glance
/opt/perf/bin/glance
OR add PATH variable in the script at the beginning to include the path.
Isnt any error reflected in the mail that you get for cron jobs ?

Regards,
Ninad
john korterman
Honored Contributor

Re: shell file doesn't run with crontab

Hi Hoang,

check that your script /script/perfcheck/checkperf.sh has registered both start and end in /var/adm/cron/log; it may not have finished.

regards,
John K.
it would be nice if you always got a second chance
Yang Qin_1
Honored Contributor

Re: shell file doesn't run with crontab

Hi, If you cannot find enough information in /var/adm/crom/log you can set debug mode in your cronjob:
00 01 * * * sh -x /script/perfcheck/checkperf.sh > /tmp/hcc1.debug

########################
ps -ef|grep glance | grep adviser |cut -c9-19 | while read name
do kill -9 $name
done
sh -x /script/perfcheck/perflog.sh > /tmp/hcc2.debug
#########################

It will record cronjob execution step by step into hcc1.debug and hcc2.debug. After you fix your problem, you can remove "-x" option.

Yang
Frank de Vries
Respected Contributor
Solution

Re: shell file doesn't run with crontab

That the logfile is created is normal, because this is part of the nohup command.
The default log is nohup.out unless you
specify an alternative log, which in your
case is done.

However, I would prefer to spawn the perflog.sh as an executable script, and
put the shell inside the script:

Thus
/script/perfcheck/perflog.sh
(chmod u+x perflog.sh)

shell identifier (must be on the first line and fields !!)
#!/sbin/sh
#set -x
GetDate=`date +"%Y%m%d"`
LOG_NM=/script/perfcheck/logfile/log.$GetDate
nohup /path/glance -j 60 -adviser_only -syntax /script/perfcheck/advfile >>$LOG_NM &
print "background PID = $! "

NB:Also use a qualified path name for glance
(but this was already mentioned)

And check if the background process has in
fact started but is not doing what you expected. In that case all works well and
the log will stay empty. It is normal behaviour. You then need to concentrate on the glance command. Try and run it manually first like this:

#nohup /path/glance -j 60 -adviser_only -syntax /script/perfcheck/advfile >>$LOG_NM &
print "background PID = $! "

If that works then we need to look further.
Otherwise trace by putting
set -x or set -xv in the perflog.sh on the second line to see what is going on.

Good luck.
Look before you leap