I smell the parsing of smbstatus -L, looking for file locks on Samba-mounted drives...
The use of split isn't quite enough, should you (like me)
happen to have users who create file names with spaces. You
have to do it in two parts, working forwards and backwards
to isolate the file name. I have some ugly code to do this.
Warning: ugly code ahead!
This is not at all bullet-proof, but feel free to adapt
the nuggets to do something better.
#! /usr/bin/perl -w
use strict;
open IN, '/usr/local/bin/smbstatus -L 2>/dev/null |'
or die "Cannot open input pipe from smbstatus: $!\n";
while( <IN> ) {
chomp;
last if /^-*$/;
}
while( <IN> ) {
chomp;
my( $pid, $mode, $rw, $oplock, $rest ) = split(' ', $_, 5);
my( $name, $dayname, $mon, $day, $timestamp, $year ) =
($rest =~ /(.*?)\s+(\S{3})\s+(\S{3})\s+(\d+)\s+(\d+:\d+:\d+)\s
++(\d+)$/);
last unless defined $pid;
print "[$pid] [$name]\n";
}
I hacked this up ages ago. I guess I should dust it off and make it a little cleaner. When I get a round tuit.
--
g r i n d e r
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.