1754976 Members
3328 Online
108828 Solutions
New Discussion юеВ

Need Help On Script

 
Venkat_33
Frequent Advisor

Need Help On Script

Hi guys,

I developed script contains i have some files like IMExxxxx and IMFxxxxx in /home/abc/test folder,
if it start IME it will go to IME Loop and for IMF will go to IMF Loop

if it goes to IME loop then after i want to find string IMCT and GWAY in IME Files

But i developed but it going on first loop only i.e IME Loop only

script is given below

#!/usr/bin/sh



export DIRECTORY=/home/abc/test
export DATETIME=`date +"%y%m%d%S"`
export IME=test_ime
export GSE=test_gse
export IMF=test_imf
export GWY=test_gwy
export TMP=tmp


for file in $( find $DIRECTORY -type f -name '*.*' | sort )
do
FNAME=`echo ${file} |cut -c 16-18`
echo $FNAME
STNG=$(awk '(NR==2) { print substr($0,34,4); }' ${file})
if [ $FNAME==IME ]
then
echo $STNG"hi"
if [ $STNG=="IMCT" ]
then
echo $STNG"IMCT Loop"
mv ${WRKFILE} ${DIRECTORY}/${IME}
elif [ $STNG==GWAY ]
then
echo $STNG"GWAY Loop"
mv ${WRKFILE} ${DIRECTORY}/${GWY}
fi
elif [ $FNAME==IMF ]
then
echo $FNAME"IMF Loop"
mv ${WRKFILE} ${DIRECTORY}/${IMF}
else
mv ${DIRECTORY}/${WRKFILE} ${DIRECTORY}/${GSE}
fi
done
3 REPLIES 3
Steven E. Protter
Exalted Contributor

Re: Need Help On Script

Shalom Sir,

if [ $FNAME==IME ]
then
echo $STNG"hi"
if [ $STNG=="IMCT" ]

...

ITRC makes this very hard to read.

But it seems that IMCT is only testted for if you get a hit on IME.

I think your if/fi structure needs to be done so all items are tested for on the first loop.

Thats not how its coded now.

Also you use of quotes is inconsistent. Good shell programmers are at least consistent. Usually its better to use them than not, though it actually makes no difference if there are no whitespaces in the output.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Venkat_33
Frequent Advisor

Re: Need Help On Script

Thanks Steven,

Now my script is working and also i started develop script just a month back.


Venkat_33
Frequent Advisor

Re: Need Help On Script

Thanks a lot