Re: Why following ksh script not works in crontab?
Posted in 1998
Let me suggest some basic debugging techniques
1) Get rid of the zeroing out of the log file and see if anything got
written there. I would suggest that there is likely nothing there. Why
zero out the file until you find out whether there is data there?
Put "set -x" as second line in the file and in the crontab file make it
read:
0 10,13 * * * mybackup_script >/tmp/log 2>&1
The /tmp/log will show each command as it is executed as well as any
output or error messages.
No, you do NOT have to background your process in cron.
Ruiming Chen wrote:
>
> The following ksh script works well in command line.
> But not work in crontab, why?
>
> -----------------------------------------------------------------------
> #!/bin/ksh
>
> # Informix back up logical log and will create a file logical.log
>
> ontape -a << EOF> ^M
> y^M
> EOF
>
> # where ^M is return input in vi by type ctrl-V and Enter
> sleep 3
>
> hour=`date +%H`
>
> if [[ $hour -ge 9 && $hour -lt 12 ]]
> then cp logical.log logical_tape1.log
> else cp logical.log logical_tape2.log
> fi
> cat /dev/null > logical.log
> -------------------------------------------------------------------
> The above script runs perfectly if on command line. But when I schedual
> in the crontab, I always got 0 (zero) size of logical_tape1/2.log. It
> seems
> to me the script does the "cp" command before the "ontape -a" processing
>
> finish. I even put a "sleep" between them. Why is that?
>
> Do I have to run the script in background in crontab? like
>
> 0 10,13 * * * mybackup_script &
>
> Currently I don't put in background "&"
>
> BTW, My OS is HP-UX 10.20, database is Informix Dynamic Server 7.3.
> For those who has OS Solaris 2.5/6.x, do you have this problem?
> To all, do you have solution for me? Thank you very much in advance!
>
> --
> RC Square Team.
>
> ------------------------------------------------------------------------
>
> Raymond/Ruiming Chui /Chen <rctwo@erols.com>
> CS
> RC Square
>
> Raymond/Ruiming Chui /Chen
> CS <rctwo@erols.com>
> RC Square HTML Mail
> U.S.A. Work: 301-498-8959
> Fax: 301-498-8959
> Home: URL http://www.erols.com/rctwo/
> Netscape Conference Address
> Netscape Conference DLS Server
> Raymond Chui & Ruiming Chen Company
> Additional Information:
> Last Name Chui /Chen
> First NameRaymond/Ruiming
> Version 2.1