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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I really need some help. 3

Status
Not open for further replies.

tijerina

Vendor
Mar 4, 2003
132
US
I have a question in the forum about output files and no answer yet. But after a full blown test of this script I realized that I have two issues, the first issue is: My second if statement is not appending to the file that I have in my first if statement. Why is this happening? My second issue is if I had more than one file missing, I only have one file listed in my output list, knowing well that I have more than one. Here is the script.

It is written in korn for an MPE HP3000 system. It works the same, but don't let the capital letters of the dir confuse you.

#!/bin/ksh -x

set -x

callci "showjob"

SERVER=`uname -n`
DATE=`date`
TOCDISC=/DJ/PUB/TOCDISC3
OUTFILE=/DJ/PUB/OUTFILE

for iii in `cat ${TOCDISC}`
do
V1=`echo ${iii}|/bin/cut -d ":" -f1`
V2=`echo ${iii}|/bin/cut -d ":" -f2`
V3=`/bin/ls -l ${V1}|awk '{print $5}'`

if [ ! -f ${V1} ]
then
print "THIS FILE WAS CREATED ON:--------${SERVER}" > OUTFILE
print "CREATION DATE IS:----------------${DATE}" >> OUTFILE
print "FILE MISSING:--------------------${V1}" >> OUTFILE
ls /SYS/PUB/LOG*
fi

if [ ${V2} -ne ${V3} ]
then
print "BYTE MISMATCH:${V1} THIS FILE HAS ${V3} BYTES" >> OUTFILE

print "YOU SHOULD HAVE: ${V2} BYTES" >> OUTFILE
print "CHECK S/W VERSION!" >> OUTFILE
fi
done



 
a) BEFORE you compute V3
check V1, if V1 is empty V3 will get an error or a lot of infos, conform to your example

b) you are (re)opening 5 time the outputfile
c) you still have doubts about {}

 
iribach,

You are too cryptic for me, I have no idea what you are saying? I come to this forum for assitance and I do appreciate all the help I get. Sometimes all I want is the answer.

Thanks,

I'll figure it out somehow..
 
What Iribach says is true.
Check that V1 is not null before getting the 5th column in V3.
Writing :
"print "THIS FILE WAS CREATED ON:-------${SERVER}" >OUTFILE"
will overwrite the contents of OUTFILE each time (+ you need $ before OUTFILE)
You need :
> $OUTFILE #create/overwrite before the for loop
and
"print "THIS FILE WAS CREATED ON:-----${SERVER}" >>$OUTFILE"

HTH
Dickie Bird (:)-)))
 
Hi,

what both say I will show implemented in your script. I guess that makes it more clear for you:
#!/bin/ksh -x

set -x

callci "showjob"

SERVER=`uname -n`
DATE=`date`
TOCDISC=/DJ/PUB/TOCDISC3
OUTFILE=/DJ/PUB/OUTFILE
> $OUTFILE #create/overwrite before the for loop

for iii in `cat ${TOCDISC}`
do
V1=`echo ${iii}|/bin/cut -d ":" -f1`
V2=`echo ${iii}|/bin/cut -d ":" -f2`
V3=`/bin/ls -l ${V1}|awk '{print $5}'`

if [ ! -f ${V1} ]
then
print "THIS FILE WAS CREATED ON:--------${SERVER}" >> $OUTFILE
print "CREATION DATE IS:----------------${DATE}" >> $OUTFILE
print "FILE MISSING:--------------------${V1}" >> $OUTFILE
ls /SYS/PUB/LOG*
fi

if [ ${V2} -ne ${V3} ]
then
print "BYTE MISMATCH:${V1} THIS FILE HAS ${V3} BYTES" >> $OUTFILE

print "YOU SHOULD HAVE: ${V2} BYTES" >> $OUTFILE
print "CHECK S/W VERSION!" >> OUTFILE
fi
done
 
Thanks to all of you and iriback, I am new at this, but because of all of you, I am getting the hang of it. It is making sense.

I get a syntax error when I run this script: This script runs okay, but the error is on the last line.

Here is the error:
+ [ 345 -ne ]
./COUNT 34: [: expression syntax error
 
I think you have null in the result of V3=`/bin/ls -l ${V1}|awk '{print $5}'`
V2 is equal to 345 and fails to compare against null
HTH

Dickie Bird (:)-)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top