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?

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.

[~] 
(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

The existing command is

last

Read about it with

man last