1

在一个脚本中,我正在运行一个返回 xml 文件的 cURL 命令。我正在尝试获取 cURL 命令的结果并用 xml2 解析它。

#! /bin/bash
# xmlParse.sh

while read line
do
   appID=`echo $line 
         | awk -F "app_id=" '{print $2}' 
         | awk '{print $1}' 
         | sed 's/\"//g'`

     # output is a numerical value, ex: 123456

   scanID=`curl --silent -u $uid:$pw $second_api_call -F app_id="$appID" 
          | awk -F "scan_id=" '{print $2}'
          | awk '{print $1}'          
          | sed 's/\"//g' 
          | sed '/^$/d' 
          | tail -1` # this grabs the last scan on the app.

    # output is a different numerical value, ex: 1234567

   get_report=`curl --silent -u $uid:$pw $last_api_call -F scan_id="$scanID"`

    # $get_report output is a report in a single line xml file.

   c_name=`"xml2 < $get_report" | grep @name= | cut -d "=" -f2`

   echo $c_name

done < <(curl --silent -u $uid:$pw $first_api_call)

我的错误看起来像:

./xmlParse.sh: line 7: xml2 < <?xml version='1.0' encoding='UTF-8'?>......
xml: File name too long

似乎它不是作为 .xml 文件读取的,而是因为整个文件是一个名称。xml 文件确实作为一行返回。我已经尝试了多种可能的解决方案,但我觉得我现在只是在给自己挖一个更深的洞,然后绕着圈子跑。当我在终端中运行命令时,它工作正常并返回如下结果:

$ xml2 < report.xml | grep @name= | cut -d "=" -f2
Data Issues
Insufficient Memory
Insufficient Memory
Insufficient Memory
RSA Algorithm 
Risky Algorithm
Code Quality
Improper Execution
Wrong Operator in String
Sensitive Information
Exposure Through Sent Data
4

0 回答 0