Script to check users logged out


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to check users logged out
# 1  
Old 03-01-2009
Script to check users logged out

Hi,

Here is the script that I have written to check if a particular user is has logged out, and if yes, then a mail needs to be sent to the management the details of whatever has been captured by the script command.

echo "The current users are:"

who | awk '{print $1}' | sort > temp1
cp temp1 temp2
more temp1

while true
do
who | awk '{print $1}' | sort > temp2
cmp -s temp1 temp2

case "$?" in


1)
user="absprod1"
file=`grep $user temp1 temp2 | cut -c 1-5`
echo $file
file1=`echo $file | cut -c 1-5`
echo $file1

if [ $file1 = "temp1" ]
then echo "User "$user" has logged out." | mail -s "Logged out" abc@xyz.com
cat /home/absprod1/test_audit | mail -s "Audit report" abc@xyz.com
fi
esac

rm temp1
mv temp2 temp1
rm /home/absprod1/test_audit
return
done


My question is how to have this script executed continuously so that, it captures every logout of the user id absprod1? Can anyone please help me?
# 2  
Old 03-03-2009
one idea is to run your script using cron, at interval of, say 5 minutes. check this

Last edited by Yogesh Sawant; 03-03-2009 at 07:30 AM.. Reason: added the link
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to find users not logged in for 90 days

Dear All, I need your help in finding out users not logged in to linux system for more than 90 days. I found a script from our forum i am getting error while using that. from the code i have debugged line by line to see where i am getting the problem. i found out the below line i am getting... (5 Replies)
Discussion started by: Sachinlinux
5 Replies

2. Shell Programming and Scripting

(RHEL, Bash) List users and check if they have logged on during the last 2 months

Hi everyone, At work we were told to check the list of users of an application server and delete all those that have left the company or don't need access to the application anymore. Here's what I came up with. Would you be as kind as to tell me your opinion and whether there is a faster / easier... (4 Replies)
Discussion started by: gacanepa
4 Replies

3. Shell Programming and Scripting

number of users logged in script

My admin needs a shell script in Korn that will show conditions based on users logged in. I have never used the Korn shell and have no clue what I am doing, can anyone help. here are the conditions that need to be returned. if users are below 5 displays should be: performance is high if... (1 Reply)
Discussion started by: vthokiefan
1 Replies

4. Shell Programming and Scripting

Script to identify logged users & commands executed

Hi All, I am trying to write a script to get the user information & the command executed. I tried something like this : w | sort | awk '{print$5$6$7}' My requirement is to identify the users who execute the same command at same time. I need the user name & the... (2 Replies)
Discussion started by: vijayarajvp
2 Replies

5. UNIX for Dummies Questions & Answers

How many users are logged in?

How do I find this out? I have a feeling its a simple command such as who, but I just don't know what it is. I've had a search on here but either I can't put it into the right search criteria or there isn't a topic on it. Thanks. EDIT: Delete this thread, as I posted it I noticed the... (0 Replies)
Discussion started by: chris_rabz
0 Replies

6. Shell Programming and Scripting

Users Not Logged in

I have searched the forums but have not mangaed to quite find what im looking for. I have used to /etc/passwd command to present me a list of all users the who command to present all users currently logged on, but what i want to know is what command can i use to display users that are registered... (12 Replies)
Discussion started by: warlock129
12 Replies

7. Post Here to Contact Site Administrators and Moderators

logged out users

how to find out users who logged out within 5 minutes (1 Reply)
Discussion started by: roshni
1 Replies

8. Shell Programming and Scripting

how many users logged

in unix what is the syntax to find out how many users are currently logged in (4 Replies)
Discussion started by: trichyselva
4 Replies

9. IP Networking

Users logged in through which NIC

We have two NIC cards in our IBM RS/6000 F50 running AIX 4.3.3 We are trying to make sure we have moved all users to log in through the new NIC. 10.22.x.y (old) 10.22.x.z (new) How can I tell which users are still using the old address for logging in so I can update their work station to... (5 Replies)
Discussion started by: cburtgo
5 Replies
Login or Register to Ask a Question