Skip to content

Instantly share code, notes, and snippets.

@krispayne
Created September 9, 2015 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krispayne/571d8849970051454d5c to your computer and use it in GitHub Desktop.
Save krispayne/571d8849970051454d5c to your computer and use it in GitHub Desktop.
#!/bin/bash
# Check for expiring password, then prompt to change with cocoaDialog
# Kris Payne
# Variables
user=`ls -l /dev/console | awk '{ print $3 }'`
pwdThreshold=7
pwdPolicy=90
CD="/Applications/Utilities/CocoaDialog.app/Contents/MacOS/CocoaDialog"
# Gather the date and find out how long we have
lastpwdMS=`dscl localhost read /Local/Default/Users/$user | grep SMBPasswordLastSet | cut -d' ' -f 2`
lastpwdUNIX1=`expr $lastpwdMS / 10000000 - 1644473600`
lastpwdUNIX=`expr $lastpwdUNIX1 - 10000000000`
todayUNIX=`date +%s`
diffDays1=`expr $todayUNIX - $lastpwdUNIX`
diffDays=`expr $diffDays1 / 86400`
daysRemaining=`expr $pwdPolicy - $diffDays`
# Run the dang dialog
if [ "$daysRemaining" -lt "$pwdThreshold" ] ; then
DIALOG=`$CD msgbox --no-newline \
--text "Your Password is Expiring Soon" \
--icon info --informative-text "Your password is expiring in $daysRemaining days. Please reset your password by choosing one of the options below. Is your computer:" \
--button1 "On Site" --button2 "Off Site" --button3 "Cancel"`
else
echo "Password older than "$pwdThreshold" days"
fi
if [ "$DIALOG" == "1" ]; then
open /System/Library/PreferencePanes/Accounts.prefPane/
elif [ "$DIALOG" == "2" ]; then
open ALTERNATE-PASSWORD-CHANGE-LOCATION
elif [ "$DIALOG" == "3" ]; then
echo "User doesn't care. NMFP."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment