Re: Why following ksh script not works in crontab?
Posted in 1998
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.
>
> ---------------------------------------------------------------
>
> Name: vcard.vcf
> Part 1.2 Type: text/x-vcard
> Encoding: 7bit
> Description: Card for Chui /Chen, Raymond/Ruiming
I agree with Jonathan and Neil about the environment. I have found (also
by bitter experience) that the only way to ensure that Informix software
works wherever it is used is to put ALL the environment settings in a
SINGLE source file and call that as a shell source (with dot). You do
this from the cron job and you can guarantee it will have the same
environment as all the rest of your programs. It would also solve the
problems posted here about the environment given to programs run by the
SPL SYSTEM statement.
If an Informix manual writer is reading this, perhaps he or she could
include the advice in the next issue? Even better, perhaps a dummy
commented file, including ALL the environment variables (they are
growing like topsy) could be sent as part of the distribution. This also
applies to the ".rc" file too. Thus would one more source of grief for
new installers be removed.
--
Peter Lancashire
Information Systems Specialist, Bayer plc
Eastern Way, Bury St Edmunds, Suffolk, IP32 7AH, UK
Tel: +44-1635-562258, Fax: +44-1635-562281
---
If all else fails, read the instructions AND the release notes.
All opinions are my own and not those of Bayer plc.
My Internet plumbing does not allow me to mail and post news together.
Sorry.
---
Join Infuse, the UK Informix User Group at http://www.infuse.org.uk/