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!

Error Redirection from system call

Status
Not open for further replies.

pmcmicha

Technical User
May 25, 2000
353
I have a gawk statement which runs some commands via system and then if they fail I have the error redirection going to another file, but nothing is being written into this file...and I am curious as to why. Could someone please review the following syntax.

COPYDIR() {
export DIR # This has to be exported or awk will not know what it is....
echo ${2}|/usr/bin/gawk -v NUM="${NUM}" -v COUNT="${COUNT}" -v CNT="${1}" -v SDI
R=&quot;${2}&quot; -v YR1=&quot;${YR1}&quot; -v BDIR=&quot;${BDIR}&quot; -v N=&quot;${N}&quot; -F&quot;_&quot; '{for (i=CNT; i <=
(NF - NUM); i++)
{(N = YR1 &quot;_&quot; $i &quot;/&quot; BDIR);
printf strftime(&quot;%T&quot;);
printf(&quot;\tNow copying files from %s to %s.....&quot;,SDIR,N);
{ if (system(&quot;/usr/bin/cp -rp ${DIR}/* 1> DIAGERR 2>&1 &quot; N &quot;/&quot;) != 0) {
printf(&quot;Failed!!!\n&quot;);
} else {
printf(&quot;Done.\n&quot;)}}}}';
}

Thanks in advance.
 
I don't see the target.
where do you copy ${DIR}/* to?

what does the text in DIAGERR say?


regards Gregor Gregor.Weertman@mailcity.com
 
DIR is passed to the gawk statement from the ksh portion of the script and it is copied to N which is also from the DIR.

Example:

DIR=2000_S_M_L_BLACK

Now in another portion of this script, the above DIR is taken and split like so:

2000_S/BLACK
2000_M/BLACK
2000_L/BLACK

At this point I need the contents under 2000_S_M_L_BLACK copied to 2000_S/BLACK, 2000_M/BLACK, 2000_L/BLACK. For the most part this works without any issues, but a few of the copies failed out and I needed to know why, but the error redirection did not work...I would like to know why. The problem after running the commands manually turned out to be that there was to much info under DIR to copy to the other directories. But DIAGERR did not report this, it was always zero in size.

So to clarify my question, can I redirect errors to files like I can with ksh in gawk? Or am I doing something incorrectly in my gawk statement?
 


When you do this:
aa = &quot;/usr/bin/cp -rp ${DIR}/* 1> DIAGERR 2>&1 &quot; N &quot;/&quot;
(your syntax)
print aa
You see
/usr/bin/cp -rp ${DIR}/* 1> DIAGERR 2>&1 target/
nok

should be
&quot;/usr/bin/cp -rp &quot; &quot;'${DIR}/*' &quot; N &quot;/ 1> DIAGERR 2>&1&quot;
then you get
/usr/bin/cp -rp SOURCE/* target/ 1> DIAGERR 2>&1
that should be ok.

(export DIR=SOURCE -> shell
N = &quot;target&quot; -> awk
)


regards Gregor

Gregor.Weertman@mailcity.com
 
That didn't quite work...the extra quotes caused this to fail.

{ if (system(&quot;/usr/bin/cp -rp &quot;'${DIR}/*'&quot; N &quot;/ 1> DIAGERR 2>&1&quot;) != 0) {

So I modified this to read:

{ if (system(&quot;/usr/bin/cp -rp ${DIR}/* &quot; N &quot;/ 1> DIAGERR 2>&1&quot;) != 0) {

But this still does not capture the errors from a failed copy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top