Thanks for the suggestions!
Meanwhile I have come up with this!
It's not fast, but it does the job!
#!/usr/bin/ksh
#####
#
# Set up Global Variables
#
#####
MIN_DAYS=2
MAX_DAYS=90
DEF_GROUP="cpx"
DATECALC="<patch_to_datecalc>"
#####
#
# Preliminary Tests
#
#####
#
# Test for the correct parameters are passed or report Usage
#
case $# in
1)
NUM_DAYS=$1
SEARCH_GROUP=$DEF_GROUP
;;
2)
NUM_DAYS=$1
SEARCH_GROUP=$2
;;
*)
echo "Usage: $(basename $0) <num_days> [ <group> ]"
exit 1
;;
esac
#
# Test that the number of days passed is in range (and therefore a number)
#
if [ ${NUM_DAYS} -lt ${MIN_DAYS} ] || [ ${NUM_DAYS} -gt ${MAX_DAYS} ]
then
echo "<num_days> (${NUM_DAYS}) should be > ${MIN_DAYS} && < ${MAX_DAYS}"
exit 1
fi
#
# Test that the group name passed exists
#
grep -q "^${SEARCH_GROUP}" /etc/group
if [ $? = 1 ]
then
echo "<group> (${SEARCH_GROUP}) not found!"
exit 1
fi
#####
#
# Declare Local Functions and populate arrays
#
#####
dateformat () {
DATE_MONTH=$(echo "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug\nSep\nOct\nNov\nDec" | grep -n $2 | awk -F':' '{print$1}')
print "$5 ${DATE_MONTH} $3"
return 0
}
#####
#
# Start the program!!!
#
#####
SEARCH_NUM=$(grep "^${SEARCH_GROUP}" /etc/group | awk -F':' '{print$3}')
TODAY=$(dateformat $(date | awk '{print $1" "$2" "$3" "$4" "$6}'))
for i in $(grep "${SEARCH_NUM}" /etc/passwd | awk -F':' '{print$1}')
do
#
# Make sure that this user has logged in before trying to process them
#
grep -p "^${i}" /etc/security/lastlog | grep -q time_last_login
if [ $? = 0 ]
then
LOGGED_DATE=$(
perl -le 'print scalar localtime shift' $(grep -p "^${i}" /etc/security/lastlog | grep time_last_login | awk '{print$3}'))
LOGGED_IN=$(dateformat ${LOGGED_DATE})
DIFF_DAYS=$(${DATECALC} -a ${TODAY} - ${LOGGED_IN})
if [ ${DIFF_DAYS} -ge ${NUM_DAYS} ]
then
typeset -L9 USER="${i}:"
typeset -R4 NUMBER=${DIFF_DAYS}
echo "${USER} ${NUMBER} days (${LOGGED_DATE})"
fi
fi
done
Of course, my AIX coding is a bit rubbish, so if anyone can see how to speed this up I would be interested.
I have used the datecalc script from this forum to perform the one date take away the other!!