1835934 Members
2105 Online
110088 Solutions
New Discussion

nohup in crontab

 
SOLVED
Go to solution
boomer_2
Super Advisor

nohup in crontab

Hi guys,
I am trying to run the below script in crontab after every 10 min...

#cat /tmp/xyzchk.sh

CC=`ls /abc/sd/r/spool/Interfaces/BATCH-UPLOADS-5|wc -l`
if [ "$CC" -ne "0" ]
then
echo "File has arrived"
/usr/bin/nohup /xyz/r/cat/script > $out/tfdrtrig.log &
else
echo "File doesnt exist"
fi

What i am doing is checking whether specific file has come and if yes then run a script in background by using nohup..
But when i am checking after file arrives,the cronjob does not run, it does not show in
ps -ef|grep script
Cronjob entry for that user test is as follows:
10,20,30,40,50,59 * * * * /tmp/xyzchk.sh > /dev/null 2>&1..the user test is already mentioned in /var/adm/cron.allow file..
12 REPLIES 12

Re: nohup in crontab


what does /var/adm/cron/log say (if anything?)

HTH

Duncan

I am an HPE Employee
Accept or Kudo
john korterman
Honored Contributor

Re: nohup in crontab

Hi,

you need to define $out
Check also the mail for the user in question and include the shell interpreter at the beginning. e.g.
#!/usr/bin/sh

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

Re: nohup in crontab

Hi,

at first do not redirect stdout/stderr to /dev/null but a file or let mail do this work.
So you can inspect your own and system generated messages.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
boomer_2
Super Advisor

Re: nohup in crontab

Hi guys,
Thanx for ur response,
i just found a similar topic and i m following raj's advice of running the script without nohup..
But now i would like to know how to
use trap in my script to ignore the hangup and exit signals.

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1038827
Dennis Handly
Acclaimed Contributor

Re: nohup in crontab

>But now i would like to know how to use trap in my script to ignore the hangup and exit signals.

A cron job isn't normally going to get a hangup signal. I'm not sure what you mean by exit?

There is a trap on exit from functions, see ksh(1)/sh(1) trap command.
boomer_2
Super Advisor

Re: nohup in crontab

Hi Dennis,
Now i am not able to run the script from cronjob without nohup...
After the file ahs arrived, the cron is not getting executed from that particular user which i have mentioned in /var/adm/cron.allow.
Dennis Handly
Acclaimed Contributor

Re: nohup in crontab

nohup shouldn't help for crontab. But if it does, it probably isn't worthwhile figuring it out why. If it works, just continue to use it.

So what works? What is your current status?
You were asked for the contents of /var/adm/cron/log.

(I assume you meant /var/adm/cron/cron.allow?)

You do know that this will send junk to stderr if it doesn't exist?
CC=`ls .../BATCH-UPLOADS-5|wc -l`

You can fix it by:
ls .../BATCH-UPLOADS-5 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "File has arrived"
boomer_2
Super Advisor

Re: nohup in crontab

Hi Dennis,
First of all let me make it clear to you as what i want to do ..

i want to run a script called xyz.sh kept in /abc/def/xyz.sh location ,only when a file arrives at /wer/thy/def location.

So im checking for /wer/thy/def locn,by taking word count if its not equal to zero that means the file has arrived and hence i m running the script called xyz.sh from /abc/def/xyz.sh .

this is a scriptm mentioned in my crontab called tfcheck.sh.


#tfcheck.sh
CC=`ls /wer/thy/def |wc -l`
if [ "$CC" -ne "0" ]
then
/abc/def/xyz.sh > $sysout/tfdrtrig.log
else
echo "File doesnot exist"
fi

MY CRONTAB entry is as follows:->
5,10,15,20,25,30,35,40,45,50,55,59 * * * * /tmp/tfcheck.sh > /dev/null 2>&1


boomer_2
Super Advisor

Re: nohup in crontab

Hi Dennis,
First of all let me make it clear to you as what i want to do ..

i want to run a script called xyz.sh kept in /abc/def/xyz.sh location ,only when a file arrives at /wer/thy/def location.

So im checking for /wer/thy/def locn,by taking word count if its not equal to zero that means the file has arrived and hence i m running the script called xyz.sh from /abc/def/xyz.sh .

this is a scriptm mentioned in my crontab called tfcheck.sh.


#tfcheck.sh
CC=`ls /wer/thy/def |wc -l`
if [ "$CC" -ne "0" ]
then
/abc/def/xyz.sh > $out/tf.log
else
echo "File doesnot exist"
fi

MY CRONTAB entry is as follows:->
5,10,15,20,25,30,35,40,45,50,55,59 * * * * /tmp/tfcheck.sh > /dev/null 2>&1


john korterman
Honored Contributor

Re: nohup in crontab

Hi again,

if your script is located in
/abc/def/xyz.sh
you better put that in your crontab entry instead of
/tmp/tfcheck.sh

regards,
John K.
it would be nice if you always got a second chance
boomer_2
Super Advisor

Re: nohup in crontab

Hi John,
The thing is that abc/def/xyz.sh in turn calls 2-3 scipts more and i can't mofidy that script...
So im using this way to run the script /abc/def/xyz.sh through cron .
Dennis Handly
Acclaimed Contributor
Solution

Re: nohup in crontab

I see you have made no progress or any changes?
The first thing you should do is remove the output redirection in the crontab:
10,20,30,40,50,59 * * * * /tmp/xyzchk.sh

The next thing you need to do is look at /var/adm/cron/log after 10 minutes and provide that result.

As mentioned by John, you need to define $out in: /abc/def/xyz.sh > $out/tf.log

Once you have these, you need to provide the cron log, your mail and tf.log.