I have a script that parses an xml in bash. I'm having a problem with one of the elements as it contains a string with some command inside of it: i.e.:
/usr/bin/printf "%b" "***** MONITORING ***** \n\n Notification Type: Critical \n Host: &{INTERNETMANAGED_URL00.URL} \n Estado: &{INTERNETMANAGED_URL00.Status} \n Time: &{INTERNETMANAGED_URL00.Status_Timestamp} Format: cyymmddhhmmssttt \n Contact to:APPSRV "|/usr/bin/mail [email protected] -c [email protected] -r "AAAAA" -s "** MONITORING - Server URL -Critical **"
How could I set that string into a variable (and print it) whithout executing the commands inside? I end up getting that printf in my output.
Thanks!
the code looks like this:
while read line
do
if [[ $line == *"SITNAME"* ]] || [[ $line == *"TEXT"* ]] ; then
flag=true
fi
if [ $flag= 'true' ]; then
echo "$line"
writeLine=$writeLine';'"$line"
fi
done < file.text
echo $writeLine >> report.out
writeLine=""
flag=false
OUTPUT ON THE ECHO
<![CDATA[/usr/bin/printf "%b" "***** MONITORING ***** nn Notification Type: Critical n Host: &{INTERNETMANAGED_URL00.URL} n Stat: &{INTERNETMANAGED_URL00.Status} n Time: &{INTERNETMANAGED_URL00.Status_Timestamp} Format: cyymmddhhmmssttt n Contact to:APPSRV "|/usr/bin/mail [email protected] -r "MONITORING" -s "** MONITORING - Server URL -Critical **"]]>
OUTPUT ON THE FILE
<![CDATA[/usr/bin/printf "%b" "***** MONITORING file1.txt readme.txt file.xml script.sh nn Notification Type: Critical n Host: &{INTERNETMANAGED_URL00.URL} n Stat: &{INTERNETMANAGED_URL00.Status} n Time: &{INTERNETMANAGED_URL00.Status_Timestamp} Format: cyymmddhhmmssttt n Contact to:APPSRV "|/usr/bin/mail [email protected] -r "MONITORING" -s "** MONITORING - Server URL -Critical **"]]>
bash
code look like? Typically, just reading text and assigning it to a variable should not execute any commands. – chepner Mar 8 at 14:01file.txt
. Is it your intent to include only lines containing "SITNAME" or "TEXT", or every line after a line containing "SITNAME" or "TEXT"? – chepner Mar 8 at 14:20