
#!/bin/sh
# File	: get_last_users.s
# By	: Maarten.deboer@atos.net, 220303
# Subject	: Script to get the usernames & more of the last users at the (Linux-)system
PGM=`basename $0|cut -d\. -f1` 
VER="0.1"
TMPCSV="/tmp/${PGM}.csv"
MAILTO="maarten.deboer@Atos.net"

cp /dev/null ${TMPCSV}
last | awk '{print $1}'|sort -u|while read USER
do
  if [ "${USER}" != "" ]; then
    USER_COMMENT=`grep ${USER} /etc/passwd|awk -F\: '{print $5}'|head -1`
# Getting the last logintime
    LAST=`last | grep ${USER}|head -1` 

# Saving info to (TMP-)file
    echo ";${USER};${USER_COMMENT};${LAST};"|tee -a ${TMPCSV}

  fi
done # while read USER

if [ "${MAILTO}" != "" ]; then
  date | mailx -a ${TMPCSV} -s "${PGM}" ${MAILTO}
  echo "  Mailed to ${TMPCSV} ${MAILTO}"
fi

echo "  CSV=${TMPCSV}"


exit 0

