Amendment to uptime script

New Contributor III

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.


dayCount=$( uptime | awk -F "(up | days)" '{ print $2 }' )

if ! [ "$dayCount" -eq "$dayCount" ] 2> /dev/null ; then

echo "<result>$dayCount</result>"

exit 0


Valued Contributor

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:


dayCount=$( uptime | awk -F "(up | days)" '{ print $2 }' )

if [[ $dayCount -gt 21 ]]; then
	jamf policy -event eventname
	echo "Uptime less than 21 days. No action taken."

exit 0

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.

Valued Contributor

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.