I have a script (let's call it "updown.sh") in /usr/local/etc/rc.d/ which does some host-specific housekeeping on startup and shutdown. One of the things it does is send email to root (forwarded to a distribution list) saying the system was shut down. I'm trying to add "by username" to that email. Here's the relevant part of the script:
As you can see, I've tried 3 different things. The $USER method returns a null string, while the other two return "root" regardless of who invoked the shutdown script. I looked in the rc(8) manpage and didn't see anything. The info exists somewhere as the broadcast message during the shutdown has the invoking user's login name.
Does anyone know where the invoking user's login name is stored and how to access it from a rc.d script?
Code:
...
# Try something different here
# echo "Host `hostname` has been shut down by `who am i | awk '{print $1}'` at `date`." | mail -s "Host `hostname` has been shut down" root 1>/dev/null 2>&1;
# Third time's the charm?
# echo "Host `hostname` has been shut down by `id -p | head -1 | cut -f 2` at `date`." | mail -s "Host `hostname` has been shut down" root 1>/dev/null 2>&1;
echo "Host `hostname` has been shut down by $USER at `date`." | mail -s "Host `hostname` has been shut down" root 1>/dev/null 2>&1;
...
Does anyone know where the invoking user's login name is stored and how to access it from a rc.d script?