Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk does not fuction into crontab 1

Status
Not open for further replies.

malpa

Technical User
Feb 8, 2004
122
CO
Hi

I want to run my programm using crontab command, but it does not function.

0 8 * * * sh path/programm.sh

But if I run the programm from command line sh programm.sh it funtion fine.

the problem ocurr when I try to run the next command using another awk.

compress" "directorio""file " | fold -w 2048 | awk -f /home/programm.awk | wc -l" | getline tamano


programm.sh

/usr/xpg4/bin/awk -v dir=${dir} -v fecha1=${fecha1} ' {

....
....


if ( file ~ /.Z$/ )
compress="zcat"
else compress="cat"
compress" "directorio""file " | fold -w 2048 | awk -f /home/programm.awk | wc -l" | getline tamano

print tamano

....

....

Any suggestion, Thanks for your help

malpa
 
This is most likely because it is running with different environment settings, especially the PATH. Try setting (and exporting) the value of PATH at the beginning of programm.sh, using a similar value to the one that you have in your interactive shell.

cron does not run your login scripts (/etc/profile, .profile, etc.) before it runs your jobs.

Annihilannic.
 
Thanks Annihilannic

After many hours,

I made some changes

0. /bin/bash
1. /usr/xpg4/bin/awk -> /usr/bin/awk
2. cmd=sprintf("%s %s%s | tr -d '"'"'\0'"'"' | fold -w224 | wc -l",compress,directorio,file) -> cmd=sprintf("%s %s%s | tr -d '"'"'\\0'"'"' | fold -w224 | wc -l",compress,directorio,file)

But , it doesnt fuction

programm.sh

#!/bin/bash
/usr/bin/awk ' {

fecha=$6;
n=split($7,ar,"/");
file=ar[n];
directorio=substr($7,1,length($7)-length(ar[n]));

if ( file ~ /.Z$/ )
compress="zcat"
else compress="cat"



cmd = (compress" "directorio""file " | fold -w 2048 | /usr/bin/awk '"'"' { i=length($0); while (i>1) { if (substr($0,i-3,3)~\"^
[0-9][0-9][0-9]$\" ) {cuenta=substr($0,i-3,3)+0;print substr($0,i-cuenta,cuenta);i=i-cuenta+1;}i-- } } '"'"' | wc -l")
cmd=sprintf("%s %s%s | tr -d '"'"'\\0'"'"' | fold -w224 | wc -l",compress,directorio,file)


} ' xxx



crontab -l

57 17 * * * /bin/bash -c '(/home/xxx/ambiente_l; /home/xxx/programm.sh 1>/home/xxx/log.DistCDR 2>/home/xxx/err.DistCDR)'


if a run this command, from my console

/bin/bash -c '(/home/xxx/ambiente_l; /home/xxx/programm.sh 1>/home/xxx/log.DistCDR 2>/home/xxx/err.DistCDR)'

The programm function fine.

ambiente_l file

export SHELL=/bin/bash
export PATH=/us/rlocal/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/ucb:/usr/ucblib:/usr/ccs/bin:/usr/openwin/bin:/usr/perl5/bin:/opt/oracle/10/bin/:/home/xxx
/

echo $SHELL
/bin/ksh


Further, I have a doubt with the double quotes.


Thanks for your suggestions

malpa

 
In what way does it "not function"? What error messages do you get?

There is no need for the "()" brackets in your bash -c command.

I think you are descending into "quote hell" with all those quotes; perhaps it would be better to move the secondary awk script out into a separate script?

Then it would look something like this if I understand your code correctly:

Code:
cmd = compress" "directorio file" | fold -w 2048 | /usr/bin/awk -f someotherscript.awk | wc -l"
cmd = sprintf("%s %s%s | tr -d \"\\0\" | fold -w224 | wc -l",compress,directorio,file)

Please post your code between [ignore]
Code:
 ...
[/ignore] tags to make it easier for us to read.

Annihilannic.
 
Hi Annihilannic

I made many mistakes

you are rigth


"""This is most likely because it is running with different environment settings, especially the PATH. Try setting (and exporting) the value of PATH at the beginning of programm.sh, using a similar value to the one that you have in your interactive shell.

cron does not run your login scripts (/etc/profile, .profile, etc.) before it runs your jobs. """"


I modified the programm including the next lines.

export SHELL=/bin/bash
export PATH=/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/ucb:/usr/ucblib:/usr/ccs/bin:/usr/openwin/bin:/usr/perl5/bin:/opt/oracle/10/bin/:

and the inner awk , I moved it out.

Further, I used a ""which"" command line to be sure.

and it function well.



Thanks a lot
malpa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top