multiline output in extension attributes bash script

Not applicable

Hi,

We're running Casper 8.3.1 and have a shell script that retrieves specific software and driver version info (not visible in Casper through normal inventory), and has about 10 lines of output when run in terminal. When setting this up to run as an Extension Attribute, all output shows on a single line (newlines removed) in JSS Inventory. Is there a way to achieve multiline output in the Inventory Details | Extension Attributes for this specific item (our other Extension Attributes have a single line of output) by inserting any special characters between <result> and </result>?

Thanks,

Bob.

-- --

Bob Grudulis
Media Production and Engineering Systems Engineer

T 415.808.9744 | C 408.242.3381
600 Harrison St San Francisco, CA 94107

PRN | media where & when it matters

This e-mail (including any attachments) is meant for only the intended recipient of the transmission, and may include confidential information. If you are not the intended recipient or you received this e-mail in error, any review, use, dissemination, distribution, or copying of this e-mail is strictly prohibited. If you have received this message in error, please notify the sender immediately by telephone at (415) 808-3500 or by return e-mail and delete this e-mail, along with any attachments and copies, from your system. Thank you.

13 REPLIES 13

sean
Valued Contributor

You should already have a special character that is being ignored; BR.

Eg. Our Graphics card reports shows the following in Extension Attributes of the Details of a machine,

NVIDIA GeForce 9600M GT
NVIDIA GeForce 9400M

Whilst the same machine when viewed through the main inventory looks like:

NVIDIA GeForce 9600M GT<BR>NVIDIA GeForce 9400M

There have already been several posts about this.

Your options are:

1) Hassle JAMF support about the feature request, which I believe is FR-0637
2) You may be able to edit the style sheet on the server to make sure it obeys the returns, like the EA page does. You will probably have to re-do this edit with each Casper update.

Sean

jarednichols
Honored Contributor

Please post your script so we can pick at it.

Thanks

j
---
Jared F. Nichols
Desktop Engineer, Client Services
Information Services Department
MIT Lincoln Laboratory
244 Wood Street
Lexington, Massachusetts 02420
781.981.5436

Not applicable

Thanks for the replies,

The really short version would be to get this type of a script to display data on two lines in the Computer Details | Extension Attributes field.

#!/bin/bash
echo "<result>";
echo "this is line 1";
echo "this is line 2";
echo "</result>";

The output we get running as a shell script (eg. In ARD):

<result>
this is line 1
this is line 2
</result>

In JSS Extended Attributes:

test: this is line 1 this is line 2

We would want to to look like this more or less:

test: this is line 1 this is line 2

I can post the actual script if need be.

Bob.

-- --

Bob Grudulis
Media Production and Engineering Systems Engineer
T  415.808.9744   |   C  408.242.3381

jarednichols
Honored Contributor

I wonder if dumping your results into an array and echoing back the array with a loop that does some proper formatting would help it out…

j
---
Jared F. Nichols
Desktop Engineer, Client Services
Information Services Department
MIT Lincoln Laboratory
244 Wood Street
Lexington, Massachusetts 02420
781.981.5436

Not applicable

I was wondering if there was a special tag or ASCII formatting character I could output between the echo statements to cause a line break to display. It does appear to ignore newline chrs. I tried adding a <br> tag at the end of "line 1" but that was interpreted as plain text:

test: line 1<br> line 2

Thanks,

Bob.

-- --

Bob Grudulis
Media Production and Engineering Systems Engineer
T 415.808.9744 | C 408.242.3381

Walter
New Contributor II

Yes, add "<br>" at the end of the text for each echo line you want to impose a line break when displayed in the JSS.
--
Walter Rowe, System Hosting
Enterprise Systems / OISM
walter.rowe at nist.gov<mailto:walter.rowe at nist.gov>
301-975-2885

sean
Valued Contributor

<BR> obeyed in EA display
<BR> ignored in Inventory display

It's right, but wrong!

If you remove the <BR> to reformat for inventory, then you mess up the EA display

Catch 22!!!

Jump on the feature request band wagon

Sean

tlarkin
Honored Contributor

Use printf instead of echo and specific new line at the end of each
command:

printf "<result>line 1/nline2/n </result>"

tlarkin
Honored Contributor

didn't finish coffee yet, use forward slashes not back slashes....

printf "<results>var1 var2 var3 </results> "

output: bash-3.2# printf "<results> var1 var2 var3 </results> " <results> var1 var2 var3 </results>

tlarkin
Honored Contributor

Wait...I meant back slashes just look at the example and I will go back
to finishing my coffee... :-)

noah_swanson
New Contributor

I attempted this and couldn't get it to work. When I run the script in the terminal it outputs fine, however in inventory results, everything is still on one line. Initially I tried <br> and that didn't work. I tried printf, but the inventory still puts everything on one line.

Has anyone been able to get this to work?

Thanks,

Noah

sean
Valued Contributor

Noah,

As said, I believe you will find that it doesn't matter what you put in for the new line, nothing will work as the style sheet for the Inventory either doesn't know to obey these characters or has possibly been coded to purposely ignore them. JAMF may have felt it is neater to not have multiple lines on the Inventory page.

I think you'll need to hassle JAMF about the feature request or try and edit the style sheet on the server.

Sean

aparten
New Contributor III

I know this is quite old and may have already been figured out, but just thought I'd post how I got it working for me should anyone discover this post years later as I did...

Piped my final code using the below (replaces new lines from the output with a " " so that printf reads it as a new line)

RESULT=$( *COMMANDS HERE* | sed -e ':a' -e 'N' -e '$!ba' -e 's/
/\n/g' )

then output using:

/usr/bin/printf "<result>$RESULT</result>"

Worked like a charm to get each result on a new line.