The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Users in AIX Lost in AIX AIX 3 06-04-2007 02:44 PM
Users In AIX Lost in AIX UNIX for Dummies Questions & Answers 1 05-24-2007 04:12 PM
Users on AIX 5.2 aldowsary AIX 4 11-06-2006 10:30 PM
Users catwomen HP-UX 1 10-12-2006 09:11 PM
do i need these users? csaunders SUN Solaris 3 04-11-2006 02:45 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-07-2006
narsing narsing is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 12
Thumbs up users of a particular dir

Hi all,

i want to know who all are using a given particular dir.

for example:

Hello is a directory, i want to find all the users who are currently accessing the hello directory.
  #2 (permalink)  
Old 02-07-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
You never mentioned which OS. This is for a /proc based system.

A very roundabout manner. Use readlink on all pids, then extract the user based on the pids from the ps listing.

Assumes a exact match between the directory to detect and the result of readlink.

Code:
[/tmp]$ cat detect.ksh
#! /bin/ksh

DIR=/dir/to/detect

cd /proc

for file in `ls -1`
do
        if [ -d "$file" ] ; then
        cd "$file"
        FIND=$(readlink -f cwd)
                if [[ "$FIND" == "$DIR" ]] ; then
                        PS_ALL="$PS_ALL $file"
                fi ;
        cd ..
        fi ;
done

echo "$PS_ALL"

# From the ps listing, get the user id from the pid

for pid in "$PS_ALL"
do
         ps -o user -p "$pid"
done

[/tmp]$
Vino
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0