2

I have the fairly common task of finding who has files open on our Linux (Ubuntu ) file server in our Windows environment.

We use Samba on the network and I use Putty from my workstation to establish a shell window to run bash scripts.

I have been using something like this to find what files are open: (this returns a list of process ids with each open file)

Robert:$ sudo lsof | grep "/srv/office/some/folder"

Then, I follow up with something like this to show who owns the process: (this returns the name of the machine on the network using the IP4 protocol who owns the process)

Robert:$ sudo lsof -p 27295 | grep "IPv4"

Now I know the windows client who has a file open and can take action from there.

As you can tell this is not difficult but time consuming. I would prefer to have a windows application I can run that would just give me what I want.

So, I have been thinking about creating some process I can run on Linux that listens on a port and then returns a clean list of all open files with the IP address of the host who has the file open. Then, a small windows client application that can send the request on the port.

It seems like this should be a very common need but I can not find anything like this that has been done before.

Any suggestions?

2

1 Answer 1

0

I. If you need to do that task on just one computer - I would do that this way:

  1. Create linux account for such tasks ("sambaadmin" for example), for better security
  2. Configure putty for automatic login on that account
  3. Write your script that does your admin tasks (/home/sambaadmin/see_clients.sh for example). I would do your tasks this way:

    smbstatus -p read -p "Press [Enter] to exit..." exit

  4. Add execute permissions to it (chmod +x /home/sambaadmin/see_clients.sh)

  5. Call this script at the end of /home/sambaadmin/.bash_profile file. .bash_profile is automatically executed after user login.

  6. Create putty shoutcut on your windows desktop for that automatic login session

After you do that - your shourtuc will open putty, log in, your "admin task script " will be executed, you will see it in putty window and after you press Enter - session will end.

II. If you use many computers in company - write simple web application in python or use some server web management software (Webmin for example).

III. You can use cron to execute every minute or two script like this:

smbstatus -p > /somewhere/sambashare/openfiles.txt

You can make shortcut to that file in windows and just open it to see what is going on.

\\sambaserver\sambashare\openfiles.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .