Skip to main content
Question

Amendment to uptime script


Forum|alt.badge.img+3

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

3 replies

Forum|alt.badge.img+14
  • Honored Contributor
  • 408 replies
  • August 17, 2022

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

Forum|alt.badge.img+3
jtrant wrote:

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

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.


Forum|alt.badge.img+14
  • Honored Contributor
  • 408 replies
  • August 17, 2022

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.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings