Script help - well, maybe not, but figured I'd check...

donmontalvo
Esteemed Contributor III

I know this is a shot in the dark, but figured I'd post this script to see if there are any ideas for getting line breaks in the output of an EA that reads the file output by the script.

High level...green initiative to set default for all installed printers to Duplex. To start, we need a report that shows what printers every user has installed that offer Duplex, and show what the default is set to.

I created a script that basically pulls a list of installed printers using lpstat, then use lpoptions to identify any that show "Duplex/", then look for the default option that is set (None, DuplexNoTumble, or DuplexTumble, an asterisk is used to show chosen default), then output to a file for each printer, containing these three possible states:

<printerName> <None> or <printerName> <DuplexNoTumble> or <printerName> <DuplexTumble>

The script...

#!/bin/sh
# Report default Duplex setting for installed printers that offer the feature.
# 20180205 Don Montalvo

# Create report folder
/bin/mkdir -p /Library/Company/SearchResults/

# Remove old reports
/bin/rm /Library/Company/SearchResults/PrinterDuplexReport-*.txt

# Get printerName for each installed printer
/usr/bin/lpstat -p | awk '{ print $2 }' > /tmp/.printersList.txt

# Go through printerName list, and report any that have duplex function,
# and include the default duplexSetting, output to a printersList.
while IFS= read -r printerName; do
    duplexSetting=$( /usr/bin/lpoptions -p "$printerName" -l | grep "Duplex/"| sed 's/.**//' | cut -f1 -d " " )
    /bin/echo "$printerName $duplexSetting" > /Library/Company/SearchResults/PrinterDuplexReport-"$printerName".txt
done < "/tmp/.printersList.txt"

# Remove printersList
if [ -e /tmp/.printersList.txt ]; then
    /bin/rm /tmp/.printersList.txt
fi

exit 0

An EA, which basically cats each of the files. Terminal shows cat output as a list. Jamf Pro shows the output as a single line. #sigh

#!/bin/sh
# Check installed printers duplex default setting.
# 20180205 Don Montalvo

defaultSetting=$( echo | cat /Library/Company/SearchResults/PrinterDuplexReport-*.txt 2>/dev/null )

if [[ $defaultSetting ]]; then
    echo "<result>"$defaultSetting"</result>"
else
    echo "<result>"NoDuplexPrintersInstalled"</result>"
fi

Sanity check, is there nothing I can do to get line returns in the output of the EA?

Gracias in advance.

Don

--
https://donmontalvo.com
5 REPLIES 5

Aaron
Contributor II

Haven't tested it, but you might be able to replace newline characters with "<br />" or "&#xA;" (newline in XML).

donmontalvo
Esteemed Contributor III

@Aaron thanks, will test this tomorrow. I was able to come up with workflow for the team who pulls the report, so they can parse out the string and get the info the report was intended to give. But yea, having a way to force line returns would be handy. At least until Jamf fixes it. :)

--
https://donmontalvo.com

mm2270
Legendary Contributor III

This is an issue Jamf needs to fix. Full stop.
I have several EAs that previously showed line breaks just fine, and then, sadly, it broke. I'm still on 9.98 here and it's broken in that release and I believe still is in version 10.x, but to be fair I haven't looked at each iteration of the new version. Jamf seems to have some difficulty with respecting line breaks consistently in their product, and it's kind of annoying. They need to address this and fix it.

Line breaks in EA output = broken
Line breaks in script output in the main policy log = broken
Line breaks in script output under individual Mac policy logs = working

Totally inconsistent.

While something like the above, formatting the output in some type of xml format or other, might work, we should not have to do that. It obviously works in some areas of Jamf Pro, so it's not like it's impossible to do. They just have to get these all aligned so they work consistently everywhere.

Here's a Feature Request to have this fixed from 9/2016 BTW that is still not even Under Review. Not encouraging to say the least.

donmontalvo
Esteemed Contributor III

Doubtful there will be any fix for Jamf Pro 9.x. :(

--
https://donmontalvo.com

donmontalvo
Esteemed Contributor III

@Aaron tested but didn't work. EAs show the strings correctly, but they don't wrap. It was worth a try though. Thanks!

--
https://donmontalvo.com