Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Splitting each word in a string

by grinder (Bishop)
on Jun 26, 2001 at 19:59 UTC ( #91639=note: print w/replies, xml ) Need Help??

in reply to Splitting each word in a string

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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://91639]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2022-01-29 14:39 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (74 votes). Check out past polls.