`history` cmd from within a bash or sh script?

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Kevin
Date:  
To: plug-discuss
Subject: `history` cmd from within a bash or sh script?
I've got a 'monitored' box that needs to send email alerts whenever a
login and logout occurs. All login accounts are heavily restricted and
use /bin/sh as their shell.

In /etc/profile I added:
who | mail -s "`hostname` LOGIN NOTICE (`whoami`)"

which sends an email with the output of the `who` command, like this:

----------------
From:
To:
Subject: pooh LOGIN NOTICE (kevin)
Date: 27 Feb 2004 10:44:41 -0701

kevin ttyp0 Feb 27 10:31 (10.10.10.1)
----------------


Customer wants the logout event to send the output of the `history`
command the same way. Since /bin/sh doesn't directly support logout
scripts the way /bin/csh does, I added the following to /etc/profile:

trap "~/.logout" 0

Then, I created a .logout file in my test user account (kevin) and did
`chmod +x ~/.logout`. In the .logout file I simply put:

history | mail -s "`hostname` LOGOUT NOTICE (`whoami`)"

However, when the `history` command is executed from the .logout file,
it appears to run in a new session, because I get this in the email:

----------------
From:
To:
Subject: pooh LOGOUT NOTICE (kevin)
Date: 27 Feb 2004 11:34:11 -0701

sh: fc: no history (yet)
----------------


Any ideas on this one?

...Kevin





---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss