Posted on 04-02-2024 10:42 AM
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?
Posted on 04-02-2024 10:56 AM
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>"
Posted on 04-02-2024 11:04 AM
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>"
Posted on 04-02-2024 01:42 PM
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.