Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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

In reply to Re: Splitting each word in a string by grinder
in thread Splitting each word in a string by chaskins

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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 or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2022-01-18 07:21 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (52 votes). Check out past polls.