
perl123soumen
New User
Jun 17, 2011, 5:50 AM
Post #3 of 3
(3777 views)
|
Re: [miller] Which process have a file open
[In reply to]
|
Can't Post
|
|
I have found a soln.; use Unix::Lsof; my $CheckUser=&CheckFile($file,$DirPathPMTA); sub CheckFile { my ($file,$DirPathPMTA)= @_; my ($output,$error) = lsof(+D,"$DirPathPMTA"); foreach $key (keys %$output) { if(( $output->{$key}->{"command name"} eq "ftp") || ( $output->{$key}->{"command name"} eq "vsftpd")) { my ($output,$error) = lsof("+p",$output->{$key}->{"process id"}); foreach $key (keys %$output) { for my $files ( @{ $output->{$key}{files} } ) { if ($files->{"file name"}=~m/$file/s) { return $files->{"file name"}; } } } } } } This checks for file access through ftp before prcoessing starts. Waiting foe enhancement of the code. Soumen
|