Posted on 06-12-2014 11:28 AM
I've mostly scripted with PowerShell and vbscript and have no experience with shell scripting, so I apologize for the newbness of this question. I'm writing an extension attribute that has a line like this:
ver='/usr/sbin/jamfds -v'
echo "<result>$ver Installed</result>"
When I run that from Terminal i see that $ver has a value of "jamfds 9.32" (which is what I expect). But when I look at a computer in the JSS I only get "/usr/sbin/jamfds -v Installed" in the value field. Any thoughts?
Solved! Go to Solution.
Posted on 06-12-2014 01:32 PM
Uhg. Okay, try grabbing both stdout and stderr.
#!/bin/sh
var=`/usr/sbin/jamfds -v 2>&1`;
/bin/echo $var;
Posted on 06-12-2014 11:42 AM
Change the ' to ` (back tick, same key as ~). So,
#!/bin/sh
ver=`/usr/sbin/jamfds -v`
echo "<result>$ver Installed</result>"
Fuller explanation: What you've actually done is set the variable ver to be a string containing /usr/sbin/jamfds -v, because you used single quotes. Using the back tick means that you want the results from that command, not the string that happens to be a command.
Posted on 06-12-2014 11:47 AM
@JPDyson
No luck with that change. Now I get this as the result:
" Installed"
It doesn't look like it's storing anything in ver now.
Posted on 06-12-2014 12:01 PM
"Jamfds" only exists on devices acting as a JDS correct?
Posted on 06-12-2014 12:02 PM
Is the shebang present at the start of the script and giving the expected shell? It could be using a different interpreter than expected. You could also try $(command_name) instead of the back ticks.
Posted on 06-12-2014 12:11 PM
@frozenarse
Yes correct. I'm writing this script to be able to create a smart computer group that lists all of the JDS's (so they can be excluded from certain policies)
@joshuasee
Yes. I have "#!/bin/sh" at the very beginning. I've tried $(command_name) with the same result. Here is the Terminal output. Seems like it's not storing the value in $var, but instead just spitting the output to the Terminal.
<HOST>:~ <USER>$ var=`/usr/sbin/jamfds -v`
jamfds 9.32
<HOST>:~ <USER>$ $var
<HOST>:~ <USER>$
<HOST>:~ <USER>$ var=$(/usr/sbin/jamfds -v)
jamfds 9.32
<HOST>:~ <USER>$ $var
<HOST>:~ <USER>$
Posted on 06-12-2014 12:19 PM
You'd have to echo at the shell to see the contents...
host$ var=`jamf version`
host$ echo $var
version=8.73
host$
Not sure what to tell you; syntax is as I said.
Posted on 06-12-2014 12:47 PM
@JPDyson
I think I see the difference. When I run "jamf version" as you did I get identical results. $var does get the version information stored in it just as you showed. But "jamfds -v" does not for some reason.
var=jamf version
does not spit out to console. Does store in $var
var=jamfds -v
Does spit out to console. Does not store in $var
Could be a difference in how JAMF coded the two binaries. I'm assuming there must be some way to get it into a variable though....
Posted on 06-12-2014 01:32 PM
Uhg. Okay, try grabbing both stdout and stderr.
#!/bin/sh
var=`/usr/sbin/jamfds -v 2>&1`;
/bin/echo $var;
Posted on 06-12-2014 01:41 PM
^^I agree with the sentiment and the fix.
Posted on 06-13-2014 06:55 AM
Perfect!
"JDS Role: jamfds 9.32 Installed"
Posted on 06-13-2014 09:03 AM
So... why is the output going to stderr in the first place?
Posted on 06-16-2014 09:25 AM
Apostate! Do not antagonize the JAMF gods, for they provide order unto the LANs, grids, and webs of the Maciverse. It is unthinkable that there would be less than perfect omnipipeance across all binaries, or that all their engineers thoughts are less than perfectly consistent.
Posted on 06-16-2014 09:29 AM
More seriously, it is an inconsistency, and I would expect the output to go the stdout since the command exits 0 and has no other output. However, I'm not sure the difference rises to the level of being a bug, not am I aware of an RFC or similar standard covering the matter.