LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Linux Admistration (https://www.linuxquestions.org/questions/linux-newbie-8/linux-admistration-804589/)

kabugima2 04-27-2010 03:11 PM

Linux Admistration
 
Which commands do you use to output the current users logged into the system and accessing a specific file?

corp769 04-27-2010 03:22 PM

who
this command will list all users logged in on your system.

ps aux | grep <username>
this will list all process by the username you supply

PTrenholme 04-27-2010 03:47 PM

This command (lsof | grep <filename> | cut -c 21-27 | sort -u) will do it. Example
Code:

$ lsof | grep /tmp | cut -c 21-27 | sort -u
Peter

You might want to look at info lsof to see what other information is available.

kabugima2 04-28-2010 12:14 PM

Adminstrative
 
suppose you want to write a shell-script that outputs a periodic listing of owners of files that are active at given times during the day, so as to monitor who was logged in when some particular event occurred e.g when someone changed the contents of files, how would you achieve this ? please help!

TB0ne 04-28-2010 01:03 PM

Quote:

Originally Posted by kabugima2 (Post 3950845)
suppose you want to write a shell-script that outputs a periodic listing of owners of files that are active at given times during the day, so as to monitor who was logged in when some particular event occurred e.g when someone changed the contents of files, how would you achieve this ? please help!

I'd use cron to run it (or make the script sleep a certain time, then loop through), and a combination of who and lsof to do the task. I'd probably have a list of files I wanted monitored, either as a text file, or hard-coded in the script, so the lsof would just check those files, or grep for it.

pixellany 04-28-2010 02:00 PM

I have merged your two closely-related threads. Please keep one thread per topic---thanks


All times are GMT -5. The time now is 04:36 PM.