Verifying Disk - Pass/Fail - Extension Attribute / Smart Groups

DanGIT
New Contributor

We want to set up a policy in Self Service to run a Verify Startup Disk. The "Completed" or "Failed" for the policy is returned into the policy logs. We’re looking for a way to get the systems into Smart Groups for "Completed" (Passed) or Failed.

2 REPLIES 2

Stevie
Contributor

Hello,

I do this at our company but as a weekly task and also via Self Service. I write the results to a plist on the computer so that I can use read the results via an Extension Attribute.

1) Setup you self service policy to run a script. If your computer disk name is not Macintosh HD then you will need to modify the script to the appropriate name.

#!/bin/sh
]whichdrive=`diskutil list | grep "Macintosh HD" | awk '{print $7}'`
theresult=`diskutil verifyVolume $whichdrive | tail -n 1 `
if [[ $theresult =~ .*corrupt.* ]]; then
    defaults write /Library/Preferences/com.yourcompany.companysettings Diskverify FAILED;
else
    defaults write /Library/Preferences/com.yourcompany.companysettings Diskverify PASSED;
fi
exit 0

2) Setup a Extension attribute to read the plist.

#!/bin/sh
HardiskStatus=`defaults read /Library/Preferences/com.yourcompany.companysettings Diskverify`
echo "<result>$HardiskStatus</result>"

Now you know the status of any given Macintosh HD at your site. I run a nightly task which looks for computers which failed the verify and set the computer to single user mode in the nvram, reboot and run an fsck. Once the has finished the script clear the nvram and restart as normal. Sometimes this does not always work so you may need to manually enter nvram boot-args="" which has happen 3 times to me last a year looking after 150 computers.

#!/bin/sh
nvram boot-args="-s"
#modify Single User mode for auto fsck -fy
echo 'if [ $HOSTNAME = localhost ] || [ -z $SECURITYSESSIONID ]; then clear; echo "Starting File System Check in 5 seconds, Control-C to quit"; /bin/sleep 6; fsckResult=$(/sbin/fsck -fy); echo "$fsckResult"; /sbin/mount -uw /; echo "$fsckResult" >> /var/log/fsck.log; /bin/rm /var/root/.profile; nvram boot-args=""; echo "Rebooting in 10 seconds."; /bin/sleep 10; /sbin/shutdown -r now; fi' > /var/root/.profile
reboot

analog_kid
Contributor

This is pretty nifty, though it seems Yosemite doesn't respect /var/root/.profile which make me a very sad panda.