Operating System - HP-UX
1752800 Members
5912 Online
108789 Solutions
New Discussion юеВ

works on command line but does not work in cron

 
SOLVED
Go to solution
amonamon
Regular Advisor

works on command line but does not work in cron

Hello..

I made one script which code I will post...script works fine from CL but in cron it has problems with second nawk. Script:

nawk -F"|" '
{ s=substr($104,2,18)}
{b[s] ++s}
END { for (i in b) print i, b[i] } ' $1 > /path/to/file/TranId_www$2


q=$(cat /path/to/file/TranId_www$2 | wc -l)
echo $q > /path/to/file/zawww


nawk -F"|" -v x=$2 -v w=$(/usr/bin/cat /path/to/file/zawww) '
{u=u+1; l=l+$66}
($66 != 0)&&($110 == 1)&&($111 == 0) { a=a+1; s=s+$66}
END { print x"|"u"|"l"|"w"|"s } ' $1 >> statistic_www


Also note that I got TranId_www$2 after script exec. in cron but statistic_www can not be appended..what might be an issue?

Pleaseeeee can anyone figure out what is problem and why does second nawk make problems??

THANKS in advance
25 REPLIES 25
James R. Ferguson
Acclaimed Contributor

Re: works on command line but does not work in cron

Hi:

Unless you have established your own PATH in your script, 'cron' has only provided a minimal one, notably:

PATH=/usr/bin:/usr/sbin:.

Make sure that you have what you think you do!

Regards!

...JRF...
Pete Randall
Outstanding Contributor

Re: works on command line but does not work in cron

As a follow-up to James' comments, the first thing that I see is "nawk", without a full path name. You have to either define a PATH or provide full path names for everything!


Pete

Pete
Peter Godron
Honored Contributor

Re: works on command line but does not work in cron

Hi,
cat and echo may be missing their paths.
do you have a correct:
/path/to/file/zawww
file ?

You could run the script in debug mode (include "set -x" as the start of the script)
to track the path of code.


DCE
Honored Contributor

Re: works on command line but does not work in cron


Cron runs with only a limited shell - be sure to fully the path to all commands.

In fact you may need to explicitly set some more environment variables that are not set by cron limited shell.

This is sometimes bypassed by using

su - -c "some command" as the line in cron in order to invoke a user's shell before the command
amonamon
Regular Advisor

Re: works on command line but does not work in cron

well my path is OK..
it is not problem with path becouse I have my other script similar almost like this one:

nawk -F"|" -v x=$2 '
{u=u+1; l=l+$66}
($66 != 0)&&($110 == 1)&&($111 == 0) { a=a+1; s=s+$66}
#$66 != 0 { a=a+1; s=s+$66}
END { print x"|"u"|"l"|"a"|"s } ' $1 >> statistic_www

and this works from my cron..so as U can see it can recognise nawk and other things..but in script from my first post first nawk is executed brcouse I can see TranId_www$2 but second is not becouse file does not append..

any better ideas?? thanks for reply
Bill Hassell
Honored Contributor

Re: works on command line but does not work in cron

All scripts, expecially in cron, should have the following code:

#!/usr/bin/sh
export PATH=/usr/bin

However, in your code, you have not specified a location for the file "statistic_www". It will need a fullpath to ensure it goes where you want it. cron runs your script on your behalf but never performs a login so none of your /etc/profile and .profile will be run. And to further troubleshoot the problem, add the command set -x at the beginning of the script.


Bill Hassell, sysadmin
john korterman
Honored Contributor

Re: works on command line but does not work in cron

Hi amonamon,

have you looked for statistic_www
in the cron user's home directory?
Does the mail to the cron user give any clue?

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

Re: works on command line but does not work in cron

hi,

I guess you have not defined which shell you are using, try defining in the first line of the script.

regards
hari
amonamon
Regular Advisor

Re: works on command line but does not work in cron

OK please...how is then possible if I am having problems with path to be able to ececute script that I published 3 posts before???
as U can see it is almost the same script no export PATH, no specificatio on shell, no path to statistic_www...and this script works just fine in cron! but script that I published in first post can not be completely executed in cron..

any clue??
thanks I hope that someone will give me a good hint which I have not tried yet.