Eric,
Nice work...
Now, I'm trying to run this from root's cron at midnight:
#!/bin/sh
#
# script to add a date stamp to the /.sh_history_$USER
# for those su'ed to root
# Only run from cron once a day
# gwild 2004-10-15
# set -x
# find parent process of all users signed in as root
for i in `ps -ef |grep "\-sh"|awk '{print $3}'`
do
# just grab the user name
USER=`ps -ef |grep $i |grep -v root|awk '{print $1}'`
# point to their .sh_history file
typeset -x HISTFILE=${HOME}/.sh_history_$USER
# time stamp it
print -s "`/usr/bin/date` $USER still logged in as root..."
unset HISTFILE
done
Unfortunatley, the print -s outputs to the first user in the list only - for all users...
tail /.sh_history_gwild
Mon Oct 18 08:55:00 MDT 2004 gwild still logged in as root...
Mon Oct 18 08:55:00 MDT 2004 user2 still logged in as root...
Mon Oct 18 08:55:01 MDT 2004 user3 still logged in as root...
ls -altr
tail .sh_history_gwild
Output with set -x:
+ ps -ef
+ grep \-sh
+ awk {print $3}
+ + ps -ef
+ grep 8983
+ grep -v root
+ awk {print $1}
USER=gwild
+ typeset -x HISTFILE=//.sh_history_gwild
+ /usr/bin/date
+ print -s Mon Oct 18 08:53:16 MDT 2004 gwild still logged in as root...
+ unset HISTFILE
+ + ps -ef
+ grep 737
+ grep -v root
+ awk {print $1}
USER=user2
+ typeset -x HISTFILE=//.sh_history_user2
+ /usr/bin/date
+ print -s Mon Oct 18 08:53:16 MDT 2004 user2 still logged in as root...
+ unset HISTFILE
+ + ps -ef
+ grep 12746
+ grep -v root
+ awk {print $1}
USER=user3
+ typeset -x HISTFILE=//.sh_history_user3
+ /usr/bin/date
+ print -s Mon Oct 18 08:53:16 MDT 2004 user3 still logged in as root...
+ unset HISTFILE
Any ideas?
Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.