Logging root sessions

Here is an addition to /etc/profile to log 'root' login sessions on AIX using the command 'script' using ksh syntax.

# Script log each session to file
# jshunter
# friday 13 - 2008

if [[ ${USER} = "root" ]]; then

# Format todays date
DTE=$(date '+%Y-%m-%d_%H.%M.%S')

# Find the pty root is logging in on
MYTERM=$(ps $$ |grep $$ |awk '{print $2}')

# Use information in who command to get hostname
MYHOST=$(who |grep ${MYTERM}|awk '{print $6}'|sed 's/[\(\)]//g')

# Fork script shell and log info into a file named with date and host
/usr/bin/script -q /var/adm/script/${DTE}-${USER}-${MYHOST}.log

# When user terminates their shell, return here, gzip the log
/usr/bin/gzip /var/adm/script/${DTE}-${USER}-${MYHOST}.log

unset DTE MYTERM MYHOST
exit
fi