Hello, I'm working on a extension attribute to tell me what version of McAfee Virus scan is installed. I got some unexpected output and tracked the problem down to the source file containing a bunch of DOS carriage returns.
How can I eliminate these characters without needing to install tools like dos2unix?
script:
#!/bin/bash
declare -x PLIST="/etc/cma.d/EPOAGENT3700MACX/config.xml"
declare -x NUMBER="$(cat "/etc/cma.d/EPOAGENT3700MACX/config.xml" | grep "<Version>.*</Version>" | sed -e 's/<Version>(.*)</Version>/1/' | awk '{print $1}' | tr -d '^M' )"
# be sure to enter ^M as ctl+v then ctl+m. the text will be blue in vi.
if [ -f "$PLIST" ] ; then
declare -x VERSION="$NUMBER"
else
declare -x VERSION="Not Installed"
echo "not installed $VERSION"
fi
echo "<results>$VERSION</results>"
exit 0
output:
bash-3.2# ./test.sh
</results>.6.0.3188
should be:
bash-3.2# ./test.sh
<results>4.6.0.3188</results>
".. tr -d '^M'.." works from a local script, however the special "^M" does not survive a copy/paste into the JSS for the extension attribute.
here is the file I'm getting the string from, I'm using the "-v" for cat to show all the hidden characters.
bash-3.2# cat -v "/etc/cma.d/EPOAGENT3700MACX/config.xml"
<?xml version="1.0" encoding="UTF-8"?>^M
<Configuration>^M
<Path>/Library/McAfee/cma/lib/libagentplugin.dylib</Path>^M
<SoftwareID>EPOAGENT3700MACX</SoftwareID>^M
<StartCommand>SystemStarter start cma</StartCommand>^M
<StopCommand>SystemStarter stop cma</StopCommand> ^M
<IsRunning></IsRunning>^M
<ProductName>McAfee Agent</ProductName>^M
<Version>4.6.0.3188</Version>^M
<Language>0409</Language>^M
<InstalledPath>/Library/McAfee/cma</InstalledPath>^M
<UninstallCommand>/Library/McAfee/cma/uninstall.sh</UninstallCommand>^M
<DebugScript>1</DebugScript> ^M
<UpdaterDataDir>/Library/McAfee/cma/scratch/update</UpdaterDataDir>^M
<ServicePackInstallDate> </ServicePackInstallDate> ^M
<ServicePackVersion> </ServicePackVersion> ^M
<HotFixInstallDate > </HotFixInstallDate> ^M
<HotFixVersions> </HotFixVersions> ^M
<PluginPkgVersion> </PluginPkgVersion> ^M
<MIDCabVersion> </MIDCabVersion>^M
<UpdatePluginPath>/Library/McAfee/cma/lib/libmacbplugin.dylib </UpdatePluginPath>^M
<keystore_path>/Library/McAfee/cma/scratch/keystore/</keystore_path>^M
<SharedLibLocation>/Library/McAfee/shared/4.6.0/lib/</SharedLibLocation>^M
<crypto_mode>2</crypto_mode>^M
<crypto_keysize>1</crypto_keysize>^M
<binsphash>[snip]</binsphash>^M
</Configuration>^M
^M
bash-3.2#