1

我有一个在 bash 中解析 xml 的脚本。我对其中一个元素有疑问,因为它包含一个字符串,其中包含一些命令:即:

/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 blabla@bla.com -c bllu@bluu.com -r "AAAAA" -s "**  MONITORING - Server URL -Critical  **"

如何在不执行内部命令的情况下将该字符串设置为变量(并打印它)?我最终在我的输出中得到那个 printf 。

谢谢!

代码如下所示:

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

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 mail@mail.com  -r "MONITORING" -s "**  MONITORING - Server URL -Critical  **"]]>

文件输出

<![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 mail@mail.com -r "MONITORING" -s "** MONITORING - Server URL -Critical **"]]>
4

1 回答 1

2

这有效:

writeLine="$writeLine"';'"$line"

...

回声“$writeLine”>>report.out

谢谢大家的时间!

于 2013-03-08T15:34:46.313 回答