Last active
January 24, 2020 19:19
-
-
Save ParadoxGuitarist/b9760d9bee908b7b39fa442604afe873 to your computer and use it in GitHub Desktop.
JAMF Extension Attribute for Days until Password Expires for Currently Logged in User.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
##################################################################################################### | |
# | |
# ABOUT THIS PROGRAM | |
# | |
# NAME | |
# Gives the number of days left until password expiration as an extension attribute. | |
# | |
#################################################################################################### | |
# | |
# HISTORY | |
# | |
# Version: 1.0 | |
# - Brian Monroe, 24.01.2020 | |
# | |
#################################################################################################### | |
# Get the home directory path of the user that's currently logged into the console. | |
UserHome="/Users/`stat -f '%Su' /dev/console`" | |
# Grabs the epoc time from the home folder when the password was last set and converts it to days. | |
DaysSinceChange=$(( ( `date +%s` - `dscl . read ${UserHome} | grep -A 1 passwordLastSetTime | grep -Eo '[0-9]{10,25}'` ) / 86400 )) | |
# Greps the days from the pwpolicy in place from JAMF | |
PolicyDays=$( pwpolicy -getaccountpolicies | grep -A 1 '<key>policyAttributeExpiresEveryNDays</key>' | grep -Eo '[0-9]+' ) | |
# Find the days left | |
DaysLeft=$(( $PolicyDays - $DaysSinceChange )) | |
# Exit if something went wrong | |
if [ ${DaysLeft} -le 0 ]; then | |
exit 0 | |
fi | |
echo "<result>${DaysLeft}</result>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment