Linux / UNIX Tech Support Forum
This is a discussion on script to record logout time within the Shell scripting forums, part of the Development/Scripting category; Hi Can anyone help that how can i record a user's logout date/time/ip? Regards Asim...
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
| Sponsored Links | ||
|
|
|
||||
|
No need to write a script, just use last command.
Linux / UNIX: Getting information about reboots and shutdowns
__________________
Vivek Gite Linux Evangelist |
|
|||
|
Yes , you are right.
But want to generate an email with information which has been written in the last command. Please see the script below this emails be when user login in. Code:
#!/bin/bash
l=`last -n 5 | awk "NR==1" | awk -F " " '{print $1, $3, $4, $5, $6, $7}'`
ip=`last -n 5 | awk "NR==1" | awk -F " " '{print $3}'`
h=`echo $HOSTNAME`
/usr/local/bin/sendEmail -t example@example.com -f example@example.com -s smtp.example.com -m $l -u Login to $h by $ip
Last edited by nixcraft; 07-06-2009 at 04:58 PM. |
|
|||
|
Dear lim,
Code:
#!/bin/bash
l=`last -n 5 | awk "NR==1" | awk -F " " '{print $1, $3, $4, $5, $6, $7}'`
ip=`last -n 5 | awk "NR==1" | awk -F " " '{print $3}'`
h=`echo $HOSTNAME`
/usr/local/bin/sendEmail -t example@example.com -f example@example.com -s smtp.example.com -m $l -u Login to $h by $ip
When a user logged in session will be recorded like this Code:
root pts/1 xxx.xxx.xxx.xxx Tue Jun 9 02:00 still logged in When a user logged out the last shows output like this: Code:
root pts/2 xxx.xxx.xxx.xxx Tue May 19 04:36 - 05:29 (00:52) awk "NR==1" | awk -F " " '{print $1, $3, $4, $5, $6, $7, $8, $9, $10}' is also fail, this will only print the very first line. So i want a command/script which search in last command and print the output of certain session. Any help please |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shell Script To Log Uptime, Connect Time, Bytes Sent Received Of a PPP Connection | dane | Shell scripting | 5 | 25-05-2009 03:28 PM |
| Script To Kill process if time and memories of more than 30% | lliriK | Shell scripting | 9 | 28-04-2009 12:43 AM |
| Thin client logout time | jhalbert | CentOS / RHEL / Fedora | 2 | 16-03-2009 10:32 PM |
| Dns MX Record | Rahul.Kolan | Domain Name Server | 2 | 08-10-2008 12:27 PM |
| Shell Script Searching For a Record In The File | vinz4ever | Shell scripting | 1 | 11-05-2008 07:35 PM |