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

Where is this thing getting it

Status
Not open for further replies.

mkjp2011

Programmer
Aug 24, 2010
15
US
Hello I created two kourne scripts on our Unix Systems.
The first script (fileListener) is called by the CRON every minute. This program waits for the existence of a trigger file (.trg). This trigger file has three lines in it, (1) Email address, (2) data file name, (3) schema file. Once it finds it it calls the second script (createEntity). Within this scrip it uses one of our vendor products to create an entity. Then the script sends the log file as a body of an email using the Email found with the trigger file. My problem is that it does complete these steps correctly. However when say there is one trigger file (it should go through once) it goes through twice, the second time however it interchanges the email read in with someone else's email. This email is something constant every time. The code follows:

filelistener
Code:
#!/bin/ksh


cd trigger

set -a entityArray[3]

count=0

for f in *.trg;
	do	  
		#echo > /export/disadm/test.out
        echo Starting > /export/disadm/test.out
		echo $f >> /export/disadm/test.out
		if [ -f $f ]; then	
			filename=$f
			base=`basename $filename .trg`
			mv $filename $base.prc
			#filename=$f
			chmod +r+w /trigger/$base.prc
			cd /export/disadm/BAT
			while read line
			do
				entityArray[$count]=$line
				echo $line >> /export/disadm/test.out
				if [[ $count -eq 3 ]]; then
					break
				fi
				count=`expr $count + 1`
			done < /trigger/$base.prc
			echo ${entityArray[0]}
			echo ${entityArray[1]}
			echo ${entityArray[2]}
			read i
			cd /export/disadm/BAT
			echo "Creating Entity" >> /export/disadm/test.out
			createentity \"${entityArray[0]}\" "Mainframe Flat Files" datafile \"${entityArray[1]}\" schemafile \"${entityArray[2]}\" national ebcdic encoding ebcdic terminator none upacked 1 
			echo "Entity Created" >> /export/disadm/test.out
		fi
    done  
echo "done" >> /export/disadm/test.out

createEntity
Code:
#!/bin/ksh

######################################################################
# Create command string
######################################################################

command="waitall [loaddata"
email=$1
echo "Email Received by: $1 " >> /export/disadm/entityAuto/outfile.out

shift 

loader=\"$1\"
echo "The Load Environment is: $1 " >> /export/disadm/entityAuto/outfile.out

shift 

echo $loader

command="${command} ${loader}" >> /export/disadm/entityAuto/outfile.out

echo = "*********Parameters*************"
while [ "$#" -gt "0" ]
do
   para1=$1
   echo "Parameter $# = ${para1}" >> /export/disadm/entityAuto/outfile.out
   shift 
   para2=$1
   echo "Parameter $# = ${para2}" >> /export/disadm/entityAuto/outfile.out
   shift 
   command="${command} ${para1} ${para2} "
done

echo "**********End Parameters**********" >> /export/disadm/entityAuto/outfile.out

command="${command}]"


############Send User Confirmation Email#######################################
#echo "I am sending" >> /exportdisadm/entityAuto/outfile.out
echo "Entity is now Successfully Created. You may now use it to do analysis." >> /export/disadm/entityAuto/outfile.out
echo "Entity Results and Notifications sent to $email" >> /export/disadm/entityAuto/outfile.out
mailx -s "Entity Creation Results" $email < /export/disadm/entityAuto/outfile.out
#echo "I am sent" >> /export/disadm/entityAuto/outfile.out
 
What is the set -a entityArray[3] supposed to do?

Why are the quotes to the createentity parameters escaped like that? Have you tried without?

I would also recommend making the output filename(s) more unique, e.g. /export/disadm/entityAuto/outfile.out.$$ to be sure that they are only being used by one run of the script. Keep in mind that they will need to be cleaned up at the end too or you'll end up with thousands of them...

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top