Skip to content

Instantly share code, notes, and snippets.

@acidprime
Created March 15, 2012 19:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save acidprime/2046271 to your computer and use it in GitHub Desktop.
Save acidprime/2046271 to your computer and use it in GitHub Desktop.
Casper Extension Attribute for number of Days of Uptime - https://jamfnation.jamfsoftware.com/editPost.html?id=19177&pid=4058&type=d
#!/bin/bash
# Commands required by this script
declare -x awk="/usr/bin/awk"
declare -x sysctl="/usr/sbin/sysctl"
declare -x perl="/usr/bin/perl"
declare -xi DAY=86400
declare -xi EPOCH="$($perl -e "print time")"
declare -xi UPTIME="$($sysctl kern.boottime |
$awk -F'[= ,]' '/sec/{print $6;exit}')"
declare -xi DIFF="$(($EPOCH - $UPTIME))"
if [ $DIFF -le $DAY ] ; then
echo "<result>1</result>"
else
echo "<result>$(($DIFF / $DAY))</result>"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment