Sunday, February 5, 2023

GREP THE S_PARAMETERS FROM CONTEXT_FILE

 #!/bin/bash


. $HOME/EBSapps.env run


# Define the path to the directory containing the XML files

dir_path='$CONTEXT_FILE'


# Define the recipient email address

email_address='recipient@example.com'


# Create a temporary file to store the HTML output

output_file=$(mktemp)


# Write the HTML header to the output file

echo '<html>' > $output_file

echo '<head>' >> $output_file

echo '<style>' >> $output_file

echo 'table {' >> $output_file

echo '  border-collapse: collapse;' >> $output_file

echo '}' >> $output_file

echo 'th, td {' >> $output_file

echo '  border: 1px solid black;' >> $output_file

echo '  padding: 8px;' >> $output_file

echo '}' >> $output_file

echo '</style>' >> $output_file

echo '</head>' >> $output_file

echo '<body>' >> $output_file


# Write the table header to the output file

echo '<table>' >> $output_file

echo '<tr>' >> $output_file

echo '<th>File Name</th>' >> $output_file

echo '<th>Line Number</th>' >> $output_file

echo '<th>s_ Parameter</th>' >> $output_file

echo '</tr>' >> $output_file


# Loop through each XML file in the directory

for file in $dir_path/*.xml; do


  # Get the filename without the path

  filename=$(basename $file)


  # Search the file for lines containing "s_"

  lines=$(grep -n "s_" $file)


  # Loop through each line

  while read -r line; do


    # Get the line number and the contents of the line

    line_number=$(echo $line | cut -d ":" -f 1)

    contents=$(echo $line | cut -d ":" -f 2-)


    # Write a table row to the output file

    echo '<tr>' >> $output_file

    echo "<td>$filename</td>" >> $output_file

    echo "<td>$line_number</td>" >> $output_file

    echo "<td>$contents</td>" >> $output_file

    echo '</tr>' >> $output_file


  done <<< "$lines"


done


# Write the HTML footer to the output file

echo '</table>' >> $output_file

echo '</body>' >> $output_file

echo '</html>' >> $output_file


# Send the HTML output as an email

mail -a "Content-Type: text/html" -s "s_ Parameters from XML Files" $email_address < $output_file


# Clean up the temporary file

rm $output_file


No comments:

Post a Comment