Need to track what Commands run in a login session


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to track what Commands run in a login session
# 1  
Old 09-02-2018
Need to track what Commands run in a login session

Hi

I need to track what commands run in login session in solaris whether it is root or any normal users in bash shell.

My actual requirement is that when a user (nomal/root) login into the system, whatever commands he run, it should log into file on specified path . I don't require command outputs. I want that in a below format.


<date and time of command run> <Actual command run along with it argument>

As I am novice in shell script, please help me in creating the same. I don't want to use snoopy or any other tool due to some constraints just want to use script for implementing the same

Regards
# 2  
Old 09-02-2018
# 3  
Old 09-02-2018
How far would setting the bash shell variable HISTTIMEFORMAT get you?


Code:
2018-09-02 11:07:06 HISTTIMEFORMAT="%F %T "
2018-09-02 11:07:08 history 5
2018-09-02 11:08:58 cat ~/.bash_history 
2018-09-02 11:09:19 history | less


You could append the history command's output to your log file periodically, and / or in ~/.bash_logout.
# 4  
Old 09-02-2018
thanks Scrutinizer for sharing the link. Yes I knew about this Solaris feature but I was more interested to implement in Script form as if got successful then I can go for implementation in Linux as well. Further this tool generate log of logs and it might bring impact on performance and bit complex to fetch the require details My only requirement is that I need what commands user has run in his session.

Thanks RudiC for sharing this idea, could you please explain how can I implement it in term of code at global level further current session commands with time should go to in a file saved with username-with logout time.

Thanks Scrutinizer & RudiC for your idea again and I would appreciate it further if you help in this further creating the script.
# 5  
Old 09-02-2018
Where are you possibly stuck?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Run automated bash commands from sh login shell

I use plink.exe to automate remote commands that return data to Windows machines. This works well on newer servers running Red Hat since the commands were developed for bash and the designated user's login shell is bash. I need to also support older servers which are running Solaris 10 but the... (5 Replies)
Discussion started by: randman1
5 Replies

2. AIX

track commands run as root after sudo

I'm looking for a way to track commands that are run as root after a user runs sudo su - root. I have a profile set up for root that will track the commands by userid but if we change the shell it only stores it in that shells history file. (2 Replies)
Discussion started by: toor13
2 Replies

3. Shell Programming and Scripting

Determining if session is a login session

Besides 'who am i' and 'tty' what commands could be used to determine if a session is interactive as compared to a web process or cron process. Any command should work with the common unix variants. (3 Replies)
Discussion started by: jgt
3 Replies

4. UNIX for Advanced & Expert Users

Track user commands

Hi, I have a unix 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 firing or... (7 Replies)
Discussion started by: mishkamima
7 Replies

5. Shell Programming and Scripting

Record login session...

How to record my login session in a file named session.lst? (1 Reply)
Discussion started by: anupdas
1 Replies

6. Solaris

I am not able to login in gnome session and java session in Sun solaris 9& 10

I am not able to login in gnome session and java session in Sun solaris 9& 10 respectively through xmanager as a nis user, I am able to login in common desktop , but gnome session its not allowing , when I have given login credentials, its coming back to login screen, what shoul I do to allow nis... (0 Replies)
Discussion started by: durgaprasadr13
0 Replies

7. UNIX for Dummies Questions & Answers

Possible to track FTP user last login? Last and Finger don't track them.

Like the topic says, does anyone know if it is possible to check to see when an FTP only user has logged in? Because the shell is /bin/false and they are only using FTP to access the system doing a "finger" or "last" it says they have never logged in. Is there a way to see when ftp users log in... (1 Reply)
Discussion started by: LordJezo
1 Replies

8. Programming

keep track of the last 10 commands the user typed

Can I do it like this? if (strcmp(argv, "history")==0) { argv = "10"; execvp(argc,argv); } actually, it doesn't work, How can I modify it? Thanks (17 Replies)
Discussion started by: zhshqzyc
17 Replies

9. UNIX for Dummies Questions & Answers

run commands before login

What would be the best way to setup for a Linux box to run a few commands before the user logs in? (1 Reply)
Discussion started by: woofie
1 Replies

10. UNIX for Advanced & Expert Users

User login session

Having a problem on AIX 4.3.3 with the following error when more than 2 users try and sign onto the server. 3004-312 All available login sessions are in use. ???? (1 Reply)
Discussion started by: Docboyeee
1 Replies
Login or Register to Ask a Question