Back in January we had a discussion here about finding the uptime of a
machine and displaying a message to users to reboot their machines. I just
wanted to follow up on that and hand out what I've done here to implement
that.
First of all, the reason I want to implement this (because I know that was a
question) is because my users have a tendency to not restart for over 7
days, some up to a month or longer. And, I get calls about performance
degradation or strange things happening. They don't even restart when I
display a message that says "Software updates have been installed, please
reboot as soon as possible."
So, here's what I've done:
- Create the following script, named it uptoolong.sh:
#!/bin/sh
# Name: uptoolong.sh
# Date: 3 March 2010
# Author: Steve Wood (swood at integer.com)
# Purpose: this script will check how long a machine has been up and display
a notification
# using Growl and Growl Notify.
# set some variables and grab the time
days=uptime | awk '{ print $4 }' | sed 's/,//g'
num=uptime | awk '{ print $3 }'
if [ $days = "days" ];
then
if [ $num -gt 5 ];
then
# I'm up too long and need a restart
/usr/sbin/jamf policy -trigger uptoolong
/usr/local/bin/growlnotify -a "Finder" -t "Restart Required" -m "Your
computer has been up for $num days. Please restart as soon as possible." -s
else
# chcek to see if somehow we restarted and left the UpTooLong receipt
if [ -e "/Library/Application Support/JAMF/Receipts/UpTooLong.pkg" ]
then
rm /Library/Application Support/JAMF/Receipts/UpTooLong.pkg
fi
fi
fi
exit 0
Create a policy that runs every day (during the week) at 11 am. The
policy runs the above script and updates inventory. It is scoped to all
computers.Create another policy with a trigger of "uptoolong" that installs a
package, UpTooLong.pkg, and updates inventory. As you can see from the
script, I use Growl with growlnotify to display a sticky note on the
computers that have been up to long asking them to please restart.Create a Smart Group that simply looks for the UpTooLong.pkg receipt.
Create a third policy that is triggered on Startup that simply removes
the UpTooLong.pkg receipt and runs inventory. This is scoped to Smart Group
in step 4.
In my testing this works perfectly. The user gets notified and hopefully
they restart their machines.
And the reason I am running update inventory so much is because I want to
make sure, regardless of if they need to restart, that I get a good
inventory every day.
Okay, now, what have I missed, or what can I do better/differently?
Steve Wood
Director of IT
swood at integer.com
The Integer Group | 1999 Bryan St. | Ste. 1700 | Dallas, TX 75201
T 214.758.6813 | F 214.758.6901 | C 940.312.2475