Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a logging question

Status
Not open for further replies.

Bangieff

Technical User
Feb 12, 2001
52
BG
Hi all
I need to create a separate log file for each user where to be stored users mail activity. Can anyone tell me how to do it?

Thanks in advance
 
Hi, Sure can

Assuming locations:

#!/bin/sh
if [ -e /var/log/mail -a -r /var/log/mail ]
then
for x in `cat usernamefile`
do
grep $x /var/log/mail > /log/usermail
done
fi

this will give you a log of all user activity.
The usernamefile is just a text file containing the names of your users.
If you have tons of users and don't feel like
writing a file that large you can write something like this to filter your password file and generate names if you have reasonable UID ranges.

awk -F&quot;:&quot; $3 < 600 && $3 > 499 {print $1}' >
usernamefile-your own ranges would be applicable of course ;)

If you want to get a little pickier you can
just add
grep &quot;username&quot; /log/usermail > /log/usrname
before the end of the for loop. You could add the awk to the script so that a new list is generated every time you add users and run the script. Just put it before the test(if).

Then you schedule this via cron.
If you want something a little fancier, you can sort and sed your way through it, or
check out the awk forum.

Luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top