natxo has asked for the wisdom of the Perl Monks concerning the following question:
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:
But this does not: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" +;
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";
Obviously, something is going wrong with the share name conversion, but I do not see what. Any help greatly appreciated.[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
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.
|
|---|