The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
clean /etc/hosts DukeNuke2 Shell Programming and Scripting 5 11-07-2006 01:42 AM
Clean File kris01752 UNIX for Advanced & Expert Users 5 09-28-2006 07:40 AM
clean up script mpang_ Shell Programming and Scripting 1 07-17-2006 08:14 PM
Clean an LV out of the ODM Wamland UNIX for Advanced & Expert Users 0 11-23-2004 12:44 PM
Directory clean up jango AIX 4 08-25-2004 06:00 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-15-2007
Registered User
 

Join Date: Oct 2007
Posts: 6
Help me clean this up

UNIX amature/novice. I've written a script (it works) that needs to be cleaned up. I'm searching for a way to perform a "go to , perform this then return" section of code. The books I have and searches i"ve done so far do not show me how to do this. I've pasted in the current code below. I've actually cut out about 75% of the actual script to keep it somewhat brief. So what I'm looking for is a way to cut out the numerous FTP and diff lines since those contain the variables.

Thanks in advance.

#!/usr/bin/ksh

# script to compare current system parameters and constants against
# a known good reference file for each stepper.
# Todd Jones - October 2007



cp blank.dat scan.dat;
cp blank.dat sum.dat;
cp blank.dat err.dat;

now=`date '+%D %T'`
echo "Nikon reference file comparison" >> sum.dat;
echo "" >> sum.dat;
echo ${now} >> sum.dat;
echo "" >> sum.dat;
echo "Files compared" >> sum.dat;
echo "Files with differnces are listed in the summary" >> sum.dat;
echo "and the diferences are appended below" >> sum.dat;
echo "" >> sum.dat


# *** open and read the stepper name

while read tool
do
if [ "${tool}" = 'nsr9' ]; then
machID='AD29018'
elif [ "${tool}" = 'nsr10' ]; then
machID='AD29028'
elif [ "${tool}" = 'nsr11' ]; then
machID='AD33005'
elif [ "${tool}" = 'nsr12' ]; then
machID='AD35001'
elif [ "${tool}" = 'nsr13' ]; then
machID='AD37005'
else
echo 'nope'
fi


# system parameter files
direct='mcsvsys.parm'

filename="mac_adjust_230.${machID}"
ftp -i nsr100 <<EOF
get ${tool}\"mcsv\ pass\"::[${direct}]${filename} ${tool}/${filename}.now
quit
EOF

diff ${tool}/${filename}.now ${tool}/${filename}.std >> temp.txt

if [ "$?" = '1' ]; then
echo "${tool} ${direct} ${filename} differences exist" >> sum.dat
echo "${tool} ${direct} ${filename}" >> scan.dat
echo "" >>scan.dat
temp.txt >> scan.dat
echo "###############################" >> scan.dat
echo "" >> scan.dat
else
echo "${tool} ${direct} ${filename}" >> sum.dat
fi


filename="sys_param_230.${machID}"
ftp -i nsr100 <<EOF
get ${tool}\"mcsv\ pass\"::[${direct}]${filename} ${tool}/${filename}.now
quit
EOF

diff ${tool}/${filename}.now ${tool}/${filename}.std >> temp.txt

if [ "$?" = '1' ]; then
echo "${tool} ${direct} ${filename} differences exist" >> sum.dat
echo "${tool} ${direct} ${filename}" >> scan.dat
echo "" >>scan.dat
temp.txt >> scan.dat
echo "###############################" >> scan.dat
echo "" >> scan.dat
else
echo "${tool} ${direct} ${filename}" >> sum.dat
fi


filename='ilm_param.ilch'
ftp -i nsr100 <<EOF
get ${tool}\"mcsv\ pass\"::[${direct}]${filename} ${tool}/${filename}.now
quit
EOF

diff ${tool}/${filename}.now ${tool}/${filename}.std >> temp.txt

if [ "$?" = '1' ]; then
echo "${tool} ${direct} ${filename} differences exist" >> sum.dat
echo "${tool} ${direct} ${filename}" >> scan.dat
echo "" >>scan.dat
temp.txt >> scan.dat
echo "###############################" >> scan.dat
echo "" >> scan.dat
else
echo "${tool} ${direct} ${filename}" >> sum.dat
fi


filename='multi_af_parameter.mpaf'
ftp -i nsr100 <<EOF
get ${tool}\"mcsv\ pass\"::[${direct}]${filename} ${tool}/${filename}.now
quit
EOF

diff ${tool}/${filename}.now ${tool}/${filename}.std >> temp.txt

if [ "$?" = '1' ]; then
echo "${tool} ${direct} ${filename} differences exist" >> sum.dat
echo "${tool} ${direct} ${filename}" >> scan.dat
echo "" >>scan.dat
temp.txt >> scan.dat
echo "###############################" >> scan.dat
echo "" >> scan.dat
else
echo "${tool} ${direct} ${filename}" >> sum.dat
fi

# *** close list to read stepper
done < nsrlist

scan.dat >> sum.dat
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-15-2007
Registered User
 

Join Date: Jul 2007
Posts: 93
sounds like you're looking for a function, you can find plenty of references on how to do this, basically:

function DoSomething
{

put in your ftp and diff commands

}

functions are defined before the main part of the program. variables are for the most part global, so you don't really need to worry about sending them to the function or returning them.

PS:
while read tool
do
if [ "${tool}" = 'nsr9' ]; then

You should really replace this large if/elif with a case statement.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0