Skip to main content

Hello All

Im trying to create an Extension Attribute that searches the JAMF log in /private/var/log for a particular word (an error code) and if its there to report a positive or negative.  Any idea of the scripting for this?  

Something like this should work as an EA returning an Integer with 0 meaning not found and 1 meaning found:

#!/bin/sh result="0" ErrorCodeFound=$(grep -w 'ErrorWord' "/private/var/log/name_of_log_file") if [ -n "$ErrorCodeFound" ]; then result="1" fi echo "<result>$result</result>"

Thanks!  So would this work if Im looking for the existence of "Error:-14167" in a log?

#!/bin/sh result="0" ErrorCodeFound=$(grep -w 'Error:-14167' "/private/var/log/jamf.log") if [ -n "$ErrorCodeFound" ]; then result="1" fi echo "<result>$result</result>"

Thanks!  So would this work if Im looking for the existence of "Error:-14167" in a log?

#!/bin/sh result="0" ErrorCodeFound=$(grep -w 'Error:-14167' "/private/var/log/jamf.log") if [ -n "$ErrorCodeFound" ]; then result="1" fi echo "<result>$result</result>"

Yep, the EA as you modified it will return 1 if "Error:-14167" is anywhere in the jamf.log file. Note that means once you've hit the error that EA will find it until the log file rolls over.