#!/bin/bash # # userpruning - a script to identify LAIR accounts that are over 2 years idle # # meant to be run on the fileserver cd /export/home now=$(date +%s) # for each user for user in `/bin/ls -1Ad [h-z]*`; do newflag="off" logage=$(cat /tmp/LAST | grep "\<${user}\>" | cut -c44-80) if [ "${logage}" = "**Never logged in**" ]; then oldness="${now}" NLI="{NLI}" else logage=$(date -d "`cat /tmp/LAST | grep \"\<${user}\>\" | cut -c44-80`" +%s) oldness=$((${now}-${logage})) NLI= fi if [ "${oldness}" -gt 63072000 ]; then # for each directory in that user's account for dir in `find ${user} -type d | tr ' ' '^' | grep -v 'Maildir' | grep -v '.pinerc'`; do dirname=$(echo ${dir} | tr '^' ' ') modate=$(stat "${dirname}" | grep '^Modify:' | cut -d' ' -f2) age=$(date -d "${modate}" +%s) oldness=$((${now}-${age})) if [ "${oldness}" -lt 63072000 ]; then echo -n "${NLI}[${user}] /home/${dirname} has " stat ${dirname} | grep '^Modify:' | cut -d' ' -f2 echo -n "Omit? " read answer if [ "${answer}" = "n" ]; then newflag="on" break fi fi done else newflag="on" fi if [ "${newflag}" = "off" ]; then echo "${NLI}${user}:${oldness}" echo "${user}:${oldness}:${NLI}" >> /tmp/usercandidatesfordeletion fi done