Posted on 08-17-2022 08:03 AM
Hi,
The below script measures uptime in days.
The result of the script looks like this in Jamf (for a Mac that been up between 5 and 6 days)
Script result: <result>5</result>
I need to amend the script so if the Script Result is more than 21 it triggers a jamf policy using events
(jamf policy -event eventname).
but I don't know how to write that script. Any help would be appreciated. Thanks.
#!/bin/sh
dayCount=$( uptime | awk -F "(up | days)" '{ print $2 }' )
if ! [ "$dayCount" -eq "$dayCount" ] 2> /dev/null ; then
dayCount="0"
fi
echo "<result>$dayCount</result>"
exit 0
08-17-2022 08:12 AM - edited 08-17-2022 08:17 AM
Is this an EA you're using for Jamf inventory or a script? If an EA, it would need to be separate to the script. Why not create a smart group with the criteria you need (uptime in days), and a policy to call your script or take whatever action you need?
Something like this would probably achieve what you want in a script:
#!/bin/bash
dayCount=$( uptime | awk -F "(up | days)" '{ print $2 }' )
if [[ $dayCount -gt 21 ]]; then
jamf policy -event eventname
else
echo "Uptime less than 21 days. No action taken."
fi
exit 0
Posted on 08-17-2022 09:01 AM
Thanks v much for that. I don't want an EA for specific reasons.
When I run your script it lists a syntax error.
Script exit code: 0
Script result: /Library/Application Support/JAMF/tmp/Uptime more than 21 days: line 5: [[: 8:47, 2 users, load averages: 2.48 2.27 2.14: syntax error in expression (error token is ":47, 2 users, load averages: 2.48 2.27 2.14")
Uptime less than 21 days. No action taken.
Posted on 08-17-2022 10:06 AM
The <result>$dayCount</result> tag in the script you provided suggested you were building an EA.
As for the script error, I'm not sure as it works fine for me. I have not added to Jamf, however.