Help needed with Asset Explorer script

Strannik
New Contributor III

For several years we've been using script to scan Macs and submit hardware and software info into our ServiceDesk Inventory. It works fine on MacOS 10.10 to 10.14, but fails in 10.15. Here is a log:

Running script Service Desk Express Inventory...
    Script exit code: 1
    Script result: ##### Scanning Started #####
/Library/Application Support/JAMF/tmp/Service Desk Express Inventory: line 21: SPE-R23-MT.xml: Read-only file system
/Library/Application Support/JAMF/tmp/Service Desk Express Inventory: line 62: SPE-R23-MT.xml: Read-only file system
/Library/Application Support/JAMF/tmp/Service Desk Express Inventory: line 63: SPE-R23-MT.xml: Read-only file system

    Error running script: return code was 1.

I think it's due to system volume being read-only in Catalina. Please help to modify the script to change the location of OUTPUTFILE.
I contacted ServiceDesk support, but they have no clue.
Here is the entire script:

#!/bin/sh

############ Server details ############

hostName="xpress.sd44.ca"
portNo="443"
protocol="https"

############ Server details ############

SUPPORT="assetexplorer-support@manageengine.com"
PRODUCT="AssetExplorer"

COMPUTERNAME=`hostname`
OUTPUTFILE="$COMPUTERNAME.xml"


main()
{
    echo "##### Scanning Started #####"
        echo "<?xml version="1.0" encoding="UTF-8" ?><DocRoot>" >$OUTPUTFILE
    constructXML "ComputerName" "hostname"
    constructXML "OS_Category" "uname -s"
    echo "<Hardware_Info>" >>$OUTPUTFILE
    constructXML "OS_Category" "sw_vers"
    constructXML "Memory_Information" "sysctl hw.physmem"
    constructXML "Memory_Information" "sysctl hw.usermem"
    constructXML "Memory_Informationw" "sysctl hw.memsize"
    constructXML "Memory_Information" "sysctl vm.swapusage"
    constructXML "Computer_Information" "hostname"
    constructXML "Computer_Information" "hostname -s"
    constructXML "CPU_Information" "system_profiler SPHardwareDataType"
    constructXML "Disk_Space" "df -k"
    constructXML "NIC_Info" "/sbin/ifconfig"
    #-----------Last logged in user name -----------
    constructXML "Last_logged_user" "last | awk '{print $1 " " $3}'"
    #-------------Chipset, VRAM, Monitor display type, resolution---------------------
    constructXML "Monitoranddisplayinfo" "/usr/sbin/system_profiler SPDisplaysDataType"
    #--------------Sound card -----------------------------
    constructXML "SoundCardinfo" "/usr/sbin/system_profiler SPAudioDataType"         
    #---------------Memory modules----------------------
    constructXML "MemoryInfo" "/usr/sbin/system_profiler SPMemoryDataType"           
    #--------------Physical drives-------------------------
    constructXML "PhysicaldrivesInfo" "/usr/sbin/system_profiler SPParallelATADataType"     
    #--------------Harddisk info if no data is available in SPParallelATADataType------------
    constructXML "HarddrivesInfo" "/usr/sbin/system_profiler SPSerialATADataType"           
    #----------------Printer Info-----------------------
    constructXML "Printer_Info" "/usr/sbin/system_profiler SPPrintersDataType -xml"           
    echo "</Hardware_Info>" >>$OUTPUTFILE
    echo "<Software_Info>" >>$OUTPUTFILE
    constructXML "Installed_Softwares" "system_profiler SPApplicationsDataType"
    echo "</Software_Info>" >>$OUTPUTFILE
    echo "</DocRoot>" >>$OUTPUTFILE
    echo "##### Scanning completed #####"
    #echo $data
    pushData
}

constructXML()
{
    ##Need to replace the < into &lt; , > into &gt; and & into &amp;#####
    echo "<$1><command>$2</command><output><![CDATA[">>$OUTPUTFILE
    eval $2 >> $OUTPUTFILE 2>&1
    echo "]]></output></$1>" >>$OUTPUTFILE
}

pushData()
{
        data=$(cat $OUTPUTFILE)
        eval "type curl > /dev/null 2>&1"

        if [ $? -ne 0 ]
        then
                echo "curl is not installed, so could not post the scan data to $PRODUCT, You can import the  $COMPUTERNAME.xml available in the current directory into $PRODUCT using Stand Alone Workstations Audit. Executing the curl command will lead to the installation."
                exit 1
        fi

    curl --header "Content-Type: text/xml" --data-binary @$OUTPUTFILE "$protocol://$hostName:$portNo/discoveryServlet/WsDiscoveryServlet?COMPUTERNAME=$COMPUTERNAME"
        if [ $? -ne 0 ]
        then
           echo "$PRODUCT is not reachable. You can import the  $COMPUTERNAME.xml available in the current directory into $PRODUCT using Stand Alone Workstations Audit. For further queries, please contact $SUPPORT."
        else
           rm -rf $OUTPUTFILE
           echo "Successfully scanned the system data, Find this machine details in $PRODUCT server."
        fi
}


main $*

Lines 21, 62 and 63 are these:
echo "<?xml version="1.0" encoding="UTF-8" ?><DocRoot>" >$OUTPUTFILE

echo "<$1><command>$2</command><output><![CDATA[">>$OUTPUTFILE

eval $2 >> $OUTPUTFILE 2>&1

The location of OUTPUTFILE is determined by <DocRoot>
How do I change that?
Regards,
Ilia

1 ACCEPTED SOLUTION

swapple
Contributor III

could you change
OUTPUTFILE="$COMPUTERNAME.xml"
to
OUTPUTFILE="/Users/Shared/$COMPUTERNAME.xml" ?

View solution in original post

3 REPLIES 3

Strannik
New Contributor III

Additional testing shows the same script runs properly on 10.15.5 computer in Terminal.
Why does it fail with read-only errors when running by Jamf policy or in Self Service?
Any ideas?

swapple
Contributor III

could you change
OUTPUTFILE="$COMPUTERNAME.xml"
to
OUTPUTFILE="/Users/Shared/$COMPUTERNAME.xml" ?

Strannik
New Contributor III

@swhps That works! Thanks a lot! I felt I need to change the path somehow...
I wonder where the OUTPUT file was created before? What is <DocRoot> location?
Anyhow, the problem is solved! One less problem to deal with...