Matlab Automation - Check if pdf is open and by which user.
5 views (last 30 days)
Show older comments
Hello,
I'm currently running a code that produces .pdf files into a server folder. These files are used by many users (50+) and overwritten daily to reflect the most recent data available.
Sometimes, users forget to close the files when leaving and it prevents the file from being overwritten by the automation. Is there a way to check if the [filename '.pdf'] is in use and by which user (similar to the MS Office Read Only and Notify feature)?
6 Comments
Jason Ross
on 10 Jun 2011
In order for this to work, you will need some administrative control on the second server. The scheme where you have server2 put the files on server1 would accomplish this goal. The key is that you want to force most clients to get this read-only.
As for the permissions "expiring", once the file is opened by someone RW, you still have to be able to kick them off.
The simplest implementation of this is a batch file that does this (on server2 -- so you would need to work out something with the admin of this server)
net share /delete <sharename>
copy \\server1\mydoc.pdf <path_that_is_shared>
net share myshare <path_that_is_shared> /GRANT:user,READ
this would be run via scheduled task.
Alternatively, you could look into using the http protocol and forgetting the whole share thing. I think it's possible to present server1's directory on server2. Then the web server takes care of presenting the files and you won't have to worry about file locks.
Accepted Answer
Jason Ross
on 1 Jun 2011
You are being too nice!
It sounds like this .pdf is intended to be used for read-only use. You can set up the share so that read-only permissions happen for the 50+ users who are accessing the document. The actual steps to accomplish this are unique on Windows or Linux, but are easy to set up. You could also investigate using using http, which sidesteps a lot of issues and makes your document accessible to any client that understands http and PDF, which includes not only PC's but also smartphones, so you can open up your data to a wider audience.
As for updating the data, that can be accomplished by a process running on the server itself or via a client that can read and write to the common location. This drops the number of clients that can hold the file open dramatically.
There are indeed means of finding this information out -- but they can require some level of administrative privilege, and even if you do find the people holding the file open, you're still going to need to somehow terminate the session -- and calling/emailing people to close their files is a non-scalable solution that eventually won't work, anyway -- for example, someone has to leave unexpectedly at 2PM and they aren't there to respond when your email comes at 5PM, and you still have to force them out somehow.
Other than the way mentioned above with read-only access, I've also used automation that deletes the share (which causes the clients to drop any locks), re-created the share, then updates the files. There are a lot of variations on this method -- such as creating the new file first, deleting the share, deleting the old file, then renaming the new file and putting up the share again.
Since you are doing this in automation, you can make this happen at 2AM, which scales nicely until you get people in different time zones who want your data :)
2 Comments
Jason Ross
on 3 Jun 2011
It's a DOS command you can put in a batch file -- NET SHARE. You can delete and re-create the share using it. You could also shell out from MATLAB and call the command, too.
More Answers (1)
See Also
Categories
Find more on Server Management in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!