Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

(RESOLVED): Filesys::SmbClient problem

by natxo (Scribe)
on Feb 13, 2014 at 10:10 UTC ( [id://1074777]=perlquestion: print w/replies, xml ) Need Help??

natxo has asked for the wisdom of the Perl Monks concerning the following question:

in order to verify if the backups are running properly I want to check timestamps of some directories in a cifs share. I need to check this from a linux host and I nearly got it working using http://search.cpan.org/~alian/Filesys-SmbClient-3.1/SmbClient.pm

If I hard code the share name, it works. I want to reuse the code allowing the share to be entered a the command line, and I hit a wall with the "$" character. In cifs (windows shares) "$" at the end of the share name means 'this share is hidden', so it is not discoverable using the Windows explorer (yes, security through obscurity).

I need to check dirs in shares with or without '$" at the end of the share name.

So using this code works:

use Filesys::SmbClient; my $smb = Filesys::SmbClient->new( username => $user, password => $pwd, workgroup => $workgroup, debug => $debug, ); my $fd = $smb->opendir("smb://filer1/db_backups\$/rest") or die "$!\n" +;
But this does not:
print "[$host], [$share], [$dir], [$user], [$pwd], [$workgroup], [$deb +ug]\n"; # change share name from share$ to share\$ if ( $share =~ m/^.*\$$/ ) { $share =~ s/\$/\\\$/g; print "share is [$share]\n"; } else { print "share is $share\n"; } my $full_path = 'smb://' . $host . '/' . $share . '/' . $dir ; print "[$full_path]\n"; my $fd = $smb->opendir("$full_path") or die "$!\n";
[filer1], [db_backups$], [rest], [user], [password], [workgroup], [100 +] share is [db_backups\$] Full path is [smb://filer1/db_backups\$/rest] No such file or directory
Obviously, something is going wrong with the share name conversion, but I do not see what. Any help greatly appreciated.

Update:

Finally resolved by using single quotes around the share name and removing the if loop that changed the sharename if it contained a $ sign. O well.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1074777]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-19 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found