问题
I am working on media management script for my environment in which I want that I should pick values from file or array for different pool and libraries, run the commands based on those inputs and mail the output based on those commands to a different people.
like, run command based on First pool, first library and then mail to the first person in file/array. or it will be great if it can match the things and need not to depend on serial order.
code is :
pool=(apple Mango Banana)
library=(lib1 lib2 lib3)
Name=(Guru Ravinder Eddy)
Email=(abc@hello.com def.@hello.com ghi@hello.com)
Subject=(India Canada Australia)
for l in "${library[@]}"
do
for p in "${pool[@]}"
do
for n in "${Name[@]}"
do
for e in "${Email[@]}"
do
for s in "${Subject[@]}"
execute a command based on pool and library > file1
and then mail to person one by one based on outputs
Output_File=/home/gsingh/MM/file556
echo "<html>" > $Output_File
echo "<title> Test" >> $Output_File
echo "</title>" >> $Output_File
echo "<body>" >> $Output_File
echo "<table border style="05">" >> $Output_File
while read line
do
echo "<tr>" >> $Output_File
echo "<td>" >> $Output_File
echo $line >> $Output_File
echo "</td>" >> $Output_File
echo "</tr>" >> $Output_File
done < "file1.txt"
echo "</table>" >> $Output_File
echo "</body>" >> $Output_File
echo "</html>" >> $Output_File
MAILTO=$e
Subject=Test
MAILFROM=guru@yoyo.com
cat - ${Output_File} <<EOF | /usr/sbin/sendmail -oi -t
From: ${MAILFROM}
To: ${MAILTO}
Subject:$s
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
EOF
Done
Done
Done
My question is that it's going in infinaite loop and even output is not correct, so trying to find best way to achive it.
来源:https://stackoverflow.com/questions/58998007/picking-up-and-matching-multiple-values-from-array-shell-scripting