- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How can I know that a file is being accessed ?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2007 07:35 AM
12-19-2007 07:35 AM
we have a HP-UX system B.11.23.
I would like to know if I can issue a statement to know if a pdf-file is being accessed by Adobe Reader.
The files are placed on a windows file-server which is mounted in our unix. Sometimes files are accessed by users (mostly using Adobe Reader).
In Windows you cannot delete a file which is being accessed. In unix the file is always deleted, even if it is being accessed. That can be a problem for us.
Is there a way in unix to know whether the file is being accessed ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2007 09:09 AM
12-19-2007 09:09 AM
Re: How can I know that a file is being accessed ?
servera:root /opt/ignite/share/doc # fuser diskmirror.pdf
diskmirror.pdf: 3440o
servera:root /opt/ignite/share/doc # ps -ef | grep 3440
root 4202 3472 1 11:08:16 pts/2 0:00 grep 3440
root 3440 3389 0 11:05:05 pts/0 0:03 /opt/Acrobat5/Reader/hppahpux/bin/acroread
Or you could do the same type of thing with lsof | grep diskmirror.pdf
servera:root /opt/ignite/share/doc # lsof | grep -i diskmirror.pdf
acroread 3440 root 24r VREG 64,0x5 67407 17271 /opt/ignite/share/doc/diskmirror.pdf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2007 10:56 AM
12-19-2007 10:56 AM
Re: How can I know that a file is being accessed ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2007 11:00 AM
12-19-2007 11:00 AM
Re: How can I know that a file is being accessed ?
In Windoze, a reader accessing the file marks it open. I assume that you are using CFS or something similar to share this Unix file system to multiple users. The Windows file system reports the file being open to the Windows system, but not to Unix.
The Unix side will delete the file do to a lack of a file lock.
You could make an enhancement to Microsoft for proper NFS file system support at version 2 or higher.. But good luck with that one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2007 11:01 AM
12-19-2007 11:01 AM
Re: How can I know that a file is being accessed ?
In Windoze, a reader accessing the file marks it open. I assume that you are using CFS or something similar to share this Unix file system to multiple users. The Windows file system reports the file being open to the Windows system, but not to Unix.
The Unix side will delete the file do to a lack of a file lock.
You could make an enhancement request to Microsoft for proper NFS file system support at version 2 or higher.. But good luck with that one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2007 11:56 AM
12-19-2007 11:56 AM
Re: How can I know that a file is being accessed ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2007 12:46 PM
12-19-2007 12:46 PM
Re: How can I know that a file is being accessed ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2007 11:59 PM
12-19-2007 11:59 PM
Re: How can I know that a file is being accessed ?
Thanks for the replies so far. I will try to clarify my issue.
We are working with an oracle application server and an oracle database which runs on a Unix server.
We have a windows-file server with pdf-files. We have written an oracle web-application where users can view the pdf-files. I want the pdf-file to be deleted after it is opened (by adobe reader).
The only way I can do this is, is by giving a Unix-command (rm) because I need to write PL/SQL that is turning on my database which is on a unix server.
The problem I am having is that when I issue the rm-command the file is not yet opened on the client, resulting in a 'no file found' (the file is deleted too early). So I need something to test if the file is being accessed, so my application can wait until the the file is accessed and then delete the file afterwards.
Best Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2007 07:21 AM
12-21-2007 07:21 AM
Re: How can I know that a file is being accessed ?
But I can't use that because I cannot test on the time. I need a status or something that tells me that the file is being accessed.
Is there some statement that gives me a status ?
Regards,
Brecht
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2007 08:24 AM
12-21-2007 08:24 AM
Re: How can I know that a file is being accessed ?
So if you could state what problem you are trying to address, maybe folks here can offer some alternatives.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2007 08:26 AM
12-21-2007 08:26 AM
Re: How can I know that a file is being accessed ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2007 10:41 AM
12-21-2007 10:41 AM
Re: How can I know that a file is being accessed ?
I have described my probem in detail in one of my previous posts (20 december). I do not know what more I can say ?
But the statement ll -u gives me almost what I need. It just gives me the time, but I cannot test on the time to see if the file is currently being accessed (as I have to wait until the file is being accessed to delete it).
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2007 07:23 AM
12-24-2007 07:23 AM
Re: How can I know that a file is being accessed ?
one other strategy that might work. Create your pdf, then create another file of the same name (but w/o the .pdf extension) like myfile.pdf and myfile. The of creation must be pdf first, then the other file.
then something like
find /
*might* work as well. I didn't check the syntax or results, so consult the man pages as necessary.
regarding your dec 20 post....yes, I read it. It seems we have our wires slightly crossed.
The statement " cannot test on the time to see if the file is currently being accessed (as I have to wait until the file is being accessed to delete it)." is closer to what I'm asking, so lets try again...
I'm looking for a description like: I have a
What I'm looking for is "
The method you've been talking about (waiting to delete until the file is accessed) has lots of potential pitfalls...for example: what does your process do if the file isn't opened in a timely fashion (i.e. user walks away, closes window or whatever)? Does it hang there waiting???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2007 11:41 AM
12-24-2007 11:41 AM
Re: How can I know that a file is being accessed ?
Sounds to me that all you need to know is whether it has been accessed.
Perhaps you can 'stat' the file and look for st_atime /* Time of last access */ being more recent than st_mtime /* Last modification time */.
IN perl you would use the "-X" file functions for those.
Unfinished perl code:
foreach (<*.rpt>) {
unlink if (-M > 1) || (-A < -M);
}
That is pick up a file to test in $_
If older then a day (1) delete.
If access less that modify then delete.
Below the signature some example values to explain. Note, the small (recent) time values are express with a float and 10 ** -5, as 1 second is 1/86400 :
$ perl -le 'print 1/86400'
1.15740740740741e-05
hth,
Hein.
$ cat > /tmp/x
aap
noot
mies
$ perl -e '$_ = shift; print -M, "\n", -A, "\n", -C , "\n"' /tmp/x
0.000162037037037037
0.000219907407407407
0.000162037037037037
$ perl -e '$_ = shift; print -M, "\n", -A, "\n", -C , "\n"' /tmp/x
0.000243055555555556
0.000300925925925926
0.000243055555555556
$ cat /tmp/x
aap
noot
mies
$ perl -e '$_ = shift; print -M, "\n", -A, "\n", -C , "\n"' /tmp/x
0.000509259259259259
8.10185185185185e-05
0.000509259259259259
$ chmod +r /tmp/x
$ perl -e '$_ = shift; print -M, "\n", -A, "\n", -C , "\n"' /tmp/x
0.000798611111111111
0.00037037037037037
4.62962962962963e-05
$ cat >> /tmp/x
teun
vuur
$ perl -e '$_ = shift; print -M, "\n", -A, "\n", -C , "\n"' /tmp/x
5.78703703703704e-05
0.000960648148148148
5.78703703703704e-05
$ cat /tmp/x
aap
noot
mies
teun
vuur
$ perl -e '$_ = shift; print -M, "\n", -A, "\n", -C , "\n"' /tmp/x
0.000428240740740741
3.47222222222222e-05
0.000428240740740741
Perl help:
-M Script start time minus file modification time, in days.
-A Same for access time.
-C Same for inode change time (Unix, may differ for other platforms)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2007 01:42 AM
12-26-2007 01:42 AM
Re: How can I know that a file is being accessed ?
I guess I can use the method given by Hein.
I will try to write a script that runs every minute or so and looks at all the files in a certain directory.
I don't know scripting in Perl very well, so I have an additional question.
How can I loop trough all the files in a directory (for example /mnt/beelden) and check them one by one if they can be deleted ?
Best regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2007 05:45 AM
12-26-2007 05:45 AM
Re: How can I know that a file is being accessed ?
Below a more complete example using perl.
Should be self explanatory
run as : perl clean.pl&
or eventually run in cron or such.
Groetjes,
Hein.
-------------------- clean.pl -------------
use warnings;
use strict;
my $stop=0;
my $total_deleted=0;
while ( ! $stop ) {
my $deleted=0;
foreach ( ) {
$stop++ if /stop/; # soft exit ?
my $modified = -M;
my $accessed = -A;
if (($modified > 1) # more than a day old?
|| ($accessed < $modified)) { # accessed after modification?
$deleted++;
unlink;
}
} # each file
$total_deleted += $deleted;
print "deleted $deleted.\n";
sleep 5 unless $stop;
} # main loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2007 05:49 AM
12-26-2007 05:49 AM
SolutionHein.
------------------------ clean.pl ----------
use warnings;
use strict;
my $stop=0;
my $total_deleted=0;
while ( ! $stop ) {
my $deleted=0;
foreach ( ) {
$stop++ if /stop/; # soft exit
my $modified = -M;
my $accessed = -A;
if (($modified > 1) # more than a day old?
|| ($accessed < $modified)) { # accessed after modification?
$deleted++;
unlink;
}
} # each file
$total_deleted += $deleted;
print "deleted $deleted.\n";
sleep 5 unless $stop;
} # main loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2007 06:45 AM
12-26-2007 06:45 AM
Re: How can I know that a file is being accessed ?
this solves my case.
Best regards,