I just want the "history" command but in a more meaningful way like recording the username and commands that user executed. The same home path will be shared by multiple users (the users I don't know, I only know that the users will share the same home path), and I want to log every user for same home path.
What I have tried is:
1. In .login file in the home path, I have redirected history to a log so that when an user logs in then the history at the point gets written to the log. Then the current user performs some commands and these are saved in history. When again logged in, any user which has same home path, the .login file will execute and the history of previous login will be logged.
But this has limitations:
- The history is duplicated, even if I delete the .history file at the home path, so a lot of duplicate data in the log file.
- History is written in next login only. So the last login will not have the commands logged.
- The log is not properly managed as the username and history are not properly mapped.
2.
2.1 Written a script: loggerscript.sh
Code:
#!/bin/csh
set logname=usercommandhist_`date +%Y%m%d_%H%M%S`.log
echo "Current user is:" $user >> $logname
script -aq $logname
2.2 Given it permission from main user:
Code:
chmod -R g+rwx $HOME/loggerscript.sh
to run in whole group.
2.3 In .login file, added
This has problems:
- Everything is logged, not just commands, the whole screen.
- 'exit' command has to be issued an extra time to stop the script by each user, and I don't want the users to know about the login.
- The data saved in log has many junk values
For example,
Quote:
[1mlinux89[0m /home/user1> ls
[0m[01;34mABC[0m [00mddr.txt[0m
|
So I hope I have explained what I am trying to do and where I am stuck.
Regards,
Raj