Script to append user details as soon as he logs in


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to append user details as soon as he logs in
# 1  
Old 04-19-2014
Script to append user details as soon as he logs in

I'm wishing to create a log myself where I wish to:
1.Write a script in /bin folder to make a separate log in var/log folder &
2.Call the script in bashrc each time a user logs in, I'm trying to avoid CRONJOB as it would take too much of my memory after iterations. So I just need to append the user details (user id, ip, date, time & duration of login)
The usage of bashrc isn't particularly clear to me and as and when someone logs in, I need that login detail to be appended to the log immediately. I think you understand what I'm trying to do without using too much of memory and space.

What script should I use? & how should I proceed with bashrc?

Last edited by Lionking93; 04-19-2014 at 07:39 PM..
# 2  
Old 04-20-2014
Hi Lionking93,

Am I missing something here, there is no need to reinvent the wheel here - there are a number of commands that can be used for this - also a number of already existing logfiles that have that data in them.

If you're determined you could write a script that gives you exactly what you want - but I think I'd advise you to look at the existing log files on your system if need be you could amend the config files like "syslogd.conf".

Or you could just put something like the following in the "/etc/profile" or create a "/etc/profile.d/custom.sh" if you want to avoid problems when you upgrade.

Code:
[~] 
(11:13:07)-(sc386dm)-(673)-> last | head -1 | awk '{ print $1" "$2" "$4" "$5" "$6" "$7 }'
sc386dm pts/8 Sat Apr 19 16:01

Obviously you'd use a redirect on the output to your logfile.

Regards

Gull04

Last edited by gull04; 04-20-2014 at 07:35 AM.. Reason: Senior Moment - couldn't spell for a one word duration!
# 3  
Old 04-20-2014
The existing command is
Code:
last

Read about it with
Code:
man last

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Fetching address and user details from log file

Hi All, I have a requirement to get the address values from a large log file along with the user details. line1,line2,city,stateCode,postalCode,countryCode. The below code as advised in the earlier post is giving the user data zgrep -B1 "Failed to calculate Tax" log.2018-05-23.gz | grep... (8 Replies)
Discussion started by: nextStep
8 Replies

2. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies

3. UNIX for Dummies Questions & Answers

Capturing the login logout details of user

Hi I'm new to Shell scripting .Can anyone please help me how to capture user's login and logout details and load them into a table... we are using Oracle DB on UNIX:confused: (3 Replies)
Discussion started by: rajmohan146
3 Replies

4. Shell Programming and Scripting

Need to run a bash script that logs on as a non-root user and runs script as root

So I have a script that runs as a non-root user, lets say the username is 'xymon' . This script needs to log on to a remote system as a non-root user also and call up a bash script that runs another bash script as root. in short: user xymon on system A needs to run a file as root user and have... (2 Replies)
Discussion started by: damang111
2 Replies

5. UNIX for Dummies Questions & Answers

Append logs to files,

i want to collect new logs only from a existing logfile and the new logs should be written both existing logfile and a new file.. which command i have to use for this. Regards Vijay, (0 Replies)
Discussion started by: vijayq8
0 Replies

6. Solaris

Command History for a user with IP details

Hi We are sharing our envoirnment with our component teams. the plateform is SunOS 5.8 Generic_117350-41 sun4u sparc SUNW,Sun-Fire-V490. All team logs in the domain with same user and perform activities. Now for the system auditing purpose can somebody guide me how can I get the details when... (6 Replies)
Discussion started by: sukhvinder_Tm
6 Replies

7. Shell Programming and Scripting

Create a script that executes when a user attempts to delete history logs

Hi, I have a linux redhat 9 server and I am concerned about the security on that server. I would like to be able to write a script that records all the commands that were typed at the command prompt before the user calls the 'history -c' command and deletes all the history. I was thinking about... (4 Replies)
Discussion started by: mishkamima
4 Replies

8. Solaris

user logon details

how can i identifying whose are logged in last few days,time and date also want. what i will do for get that information (2 Replies)
Discussion started by: sijocg
2 Replies

9. Shell Programming and Scripting

Script to delete logs or take backups under specific user

I have to write a shell script like this-- 1) Utility will be run under the directory owner. 2) This utility will clean files in ABC/logs. And following logs will be backed up or deleted. Dispatcher Logs Middle tier Logs Sage log Sage monitor log Sage db clean up result log Core files ... (12 Replies)
Discussion started by: namishtiwari
12 Replies

10. Shell Programming and Scripting

Perl log parcer. (for custom logs details inside)

OS:sol8 ok 2 things are very important. I will give examples of the logs and the client file for testing. Object: to display on the web sometime to parse your custom logs basied on the inputed date and client selected. I know alot of ppl are like who care. but i saw a perl script on here... (1 Reply)
Discussion started by: Optimus_P
1 Replies
Login or Register to Ask a Question