Red HatThis forum is for the discussion of Red Hat Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
In the .logout file add this line
-----------------------------------
echo logout time `date`>> .daylogs/masterlog
This script assumes you have a hidden
directory called .daylogs this helps keep it out of sight and away from prying eyes and if you keep root ownership of the directory change the mode to:
chmod 744 .daylogs
This will not allow anyone to get in to the directory to look around.
.login and .logout are files that would be created in each user's home directory. They are basically just script files that get sourced at login time. If you are trying to track this for all users you might want to put it into /etc/csh.login and /ec/csh.logout as those are sourced by all users. That way you wouldn't have to add anything to each user.
Having said that please note that .login and .logout are used only by people that use csh or tcsh as their shell. People using bash (the default in most Linux distros) use different files (.profile and others). You'll want to verify which shell the user accounts are using. (Each user can have a different one.)
If you put it in /etc/csh.login you should probably modify it to have:
if [ ! -d $HOME/.daylogs ]
then mkdir $HOME/.daylogs
fi
echo login time `date` >> .daylogs/masterlog
The above will check to be sure the directory exists and if not will create it. If you're really trying to log users though you might want to consider putting this log somewhere OUTSIDE their home directory so that they don't see it with a simple ls -la of the home directory. You'd then want to add a username componet to distinguish from other users like so:
echo login time `date` $LOGNAME >> .daylogs/masterlog
Going on to the rest of what you wrote - note that the individual "grep" commands you're showing should be on separate lines or separate with semi-colons:
grep -i "sun" .daylogs/masterlog > .daylogs/sunday.log ; grep -i "mon" .daylogs/masterlog > .daylogs/monday.log ...
My advice would be separate lines to make it easier to read later.
However if you run the grep on every login its going to duplicate information the daylogs. You'd need to work out a more sophisticated grep tha only got the most recent information. Personally I don't see the value in the daylogs. Any time you need to see information for a specific day you can grep it fom he masterlog from the command line just by tryping the grep command.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.