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!

if statement

Status
Not open for further replies.

tijerina

Vendor
Mar 4, 2003
132
US
Below is a script that I am using to audit a dir against a static file. It works and all. So what i am doing is switching the system log in the begginning so we can close out current log and create a new one. If certain conditions are met via an if statement, then I will copy logfiles from one dir to another. But how do I only do this once? You see, within my static file, I have about 400 files to audit against. A file beginning with the letter "A" is missing, the script will do what the if statements says to do, and then copy according to one of the if statements. Now we get to a file starting with the letter "T" and this is missing, we have to repeat the entire process of copying over the same log files. How do I only do this once?

#!/bin/ksh -x

set -x

callci "switchlog"

TOCDISC=/DJ/PUB/TOCDISC

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

if [ ! -f ${V1} ]
then
print "File Missing: ${i}${V1}...."
fi

if [ ! -f ${V1} ]
then
cp /SYS/PUB/LOG* /TELESUP/PUB/
fi

if [ ${V2} -ne ${V3} ]
then
print "File: ${i} has a mismatched byte count!! Current count:
${V3}.....Please Correct!!!"
fi
done
 
set -x

# i dont know what this does sure the " are superfluos
# callci "switchlog"

# try to write readable && easy to mantain code
# prouve you know the use of {}
# this is NEEDED: ${a}bba ${a}_bba
# NOT NEEDED, NOR WRONG but CONFUSING: ${a}.bba ${a}/bba ${a}:bba ${a}${b}
# do not use var-names like i, iii costs nothing, and
# suppose you HAVE to replace the i in a 10.000 line code file :)
# be congruent
# if you say /bin/cut, say also /bin/echo, /bin/awk, /bin/cat ...
# or do not use /bin/ and set the PATH according your needs
# test your results
# print is a ksh builtin, use system cmds like: /bin/printf (need \n)
# or /bin/echo for portability
# the if-elif-else-fi is the worstest construct in every languages
# very hard to (correctly) interprete and cause of many problems

TOCDISC=/DJ/PUB/TOCDISC

for iii in `cat $TOCDISC`
do
[ x$V1 = x ] && echo V1 is empty && continue
[ x$V2 = x ] && echo V2 is empty && continue

if [ ! -f $V1 ]
then
echo "File Missing: $iii/$V1...."
# cp /SYS/PUB/LOG* /TELESUP/PUB/
# supposed /TELESUP/PUB is a directory
# i do not know what this is: /SYS/PUB/LOG*
cp /SYS/PUB/LOG* /TELESUP/PUB
continue
fi

V3=`/bin/ls -s $V1|awk '{print $1;}'`

#change your stat-files; better is
# V3=`/bin/ls -l $V1|awk '{print $5;}'`
# ls -s prints block, not size
# a file 400bytes large is 1 block
# a file 4bytes large is still 1 block
# a file 513bytes large is 2 block
# a file 900bytes large is still 2 block

[ x$V2 = x$V3 ] && continue
echo "File: $iii has a mismatched byte count!!"
echo "Current count: $V3.....Please Correct!!!"
done
 
Hello iribach,

Thank you for your assistnace and I tried your suggestion and this is what I got. It is telling me that V1 is empty and I know it should not be empty. Am I doing anything wrong? Way below is the script.

--------------Message I get in DEBUG mode--------------

+ TOCDISC=/DJ/PUB/TOCDISC
+ echo You are now auditing the DISC account for OMNIDEX. Please Wait
You are now auditing the DISC account for OMNIDEX. Please Wait
+ cat /DJ/PUB/TOCDISC
1> /tmp/sh025901CA.aaa
+ [ x = x ]
+ echo V1 is empty
V1 is empty

-------------End of Message in DEBUG Mode---------------


----------Start of Script------------------------------

#!/bin/ksh -x

set -x

callci "showjob"

TOCDISC=/DJ/PUB/TOCDISC

echo "You are now auditing the DISC account for OMNIDEX. Please Wait"

for iii in `cat ${TOCDISC}`
do
[ x$V1 = x ] && echo V1 is empty && continue
[ x$V2 = x ] && echo V2 is empty && continue

if [! -f $V1]
then
echo "File Missing:$iii/$V1..."
cp /SYS/PUB/LOG* /TELESUP/PUB
continue
fi
V3=`/bin/ls -l $V1|awk '{print $5;}'`
[ x$V2 = x$V3 ] && continue
echo "File: $iii has a mismatched byte count!!"
echo "Current Count: $V3..... Please Correct!!!"
done

----------------End of copy and paste of script------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top