0611 auto sorting and resend script

#!/bin/bash 

executeDate=$(date +%H%M_%m%d_%Y)

#output/0646_0627_2022/

#遍历出某个文件夹下的所有文件夹内的相对路径文件名
function traverseTheFilenameArray { 
	echo -n "Enter the directory path, like output/0506_0611_2022 : "
	read directoryPath
	filenameArray=""
	for file in "$directoryPath"/*
	do
		if [ -d $file ]
		then
			for subFile in "$file"/*
			do
				#echo $subFile
				filenameArray="$filenameArray","$subFile"
			done
		fi
	done

filenameArray=${filenameArray:1}
echo "fileName=" $filenameArray
} 

#根据log,和里面的sender 来分类和重发messgaes
function resendMessagesByTheLogFile { 

	mkdir -p output/$executeDate
	echo executeDate: $executeDate

	if [ ! -f "output/$executeDate/senderList.txt" ]; 
	then
	awk 'BEGIN{FS="\"";}
	/ERROR/&&/{"customerNumber":"/{x[$8]=$8;}
	END{for( i in x) print x[i] >> "output/" "'"$executeDate"'" "/senderList.txt";}' bsc-custom-reply-handler.log
	else
		echo "senderList already exists at this executeDate, could you run it next minute?"
	fi

	for sender in `cat output/$executeDate/senderList.txt`
		do
			mkdir -p output/$executeDate/$sender;
			senders+=,$sender;
			awk 'BEGIN{FS="Message received : ";lineCounter=1;filenameArray=filename;} 

			/ERROR/&&/{"customerNumber":"/&&/"'"$sender"'"/{
			filename="resendMessage" lineCounter ".txt";
			filenameArray=filenameArray",output/" "'"$executeDate"'" "/" "'"$sender"'" "/" "'"$sender"'" filename;
			print $2 > "output/" "'"$executeDate"'" "/" "'"$sender"'" "/" "'"$sender"'" filename;
			lineCounter++;
			} 
			END{print "sender: "'"$sender"'" message files Count: " lineCounter-1}' handle.log

		done
	RawFilenameArray=`echo output/$executeDate | traverseTheFilenameArray` 
	echo ${RawFilenameArray:55}>> $propertiesVersion

	senders=${senders:1}
	echo senders list: $senders
	unset senders

	echo -n pleace check the filenames in $propertiesVersion . Enter "y" to continue, otherwise it will quit.
	read ifExecuteJava
	
	if [ $ifExecuteJava = y ]
	then
		"/opt/IBM/WebSphere90/AppServer/java/8.0/jre/bin/java"  -Djava.library.path=/opt/mqm/java/lib64/ -classpath "/opt/mqm/java/lib/com.ibm.mq.jar:./" PutMessageBindings $propertiesVersion 2>&1 | tee output/$executeDate/javaResult.txt

		echo Java result count: $(sed -n '/customerNumber/p' output/$executeDate/javaResult.txt | wc -l) 
		echo You can see your output files are all in output/$executeDate/

	else
		exit
	fi
} 


#二级菜单
function envChoosing { 
PS3="hit 'enter' to display menu again. you can see the environment settings in 'dontChangeTemplates/*.properties'. Enter option:" 

select option in "UAT" "PROD" "Back to the Previous Level" 
do 
	case $option in 
	"Back to the Previous Level")
		PS3="hit 'enter' to display menu again. Remember execute this .sh file on the server according to the properties file. Enter option: "   
		break ;; 
	"UAT") 
		propertiesVersion=""$executeDate"_UatAoPutMessageBindings.properties"
		cp dontChangeTemplates/UatAoPutMessageBindings.properties $propertiesVersion
		echo $propertiesVersion created
		echo $(sed -n '/mqHostName/p' $propertiesVersion)
		echo $(sed -n '/mqManager/p' $propertiesVersion)
		resendMessagesByTheLogFile ;; 
	"PROD") 
		propertiesVersion=""$executeDate"_PutMessageBindings.properties"
		cp dontChangeTemplates/PutMessageBindings.properties $propertiesVersion
		echo $propertiesVersion created
		echo $(sed -n '/mqHostName/p' $propertiesVersion)
		echo $(sed -n '/mqManager/p' $propertiesVersion)
		resendMessagesByTheLogFile ;; 
	*) 
		clear 
		echo "Sorry, wrong selection";; 
	esac 
done 

} 

#菜单
PS3="hit 'enter' to display menu again. Remember execute this .sh file on the server according to the properties file. Enter option: " 

select option in "Resend messages by bsc-custom-reply-handler.log" "traverse the filename array of a spec directory" "Exit program" 
do 
	case $option in 
	"Exit program") 
		break ;; 
	"Resend messages by bsc-custom-reply-handler.log") 
		envChoosing ;; 
	"traverse the filename array of a spec directory") 
		traverseTheFilenameArray ;; 
	*) 
		clear 
		echo "Sorry, wrong selection";; 
	esac 
done 

你可能感兴趣的:(linux)