Hi Perlmonks,
I'm developing a perl script on M$ for temporarily mapping a drive and then using robocopy to copy over a file I created to the NAS. Because of 2012 windows junk robocopy is choking with access denied errors without a drive mapping to the full unc path prior to executing the robocopy. pushd doesn't work and neither does net use without a drive letter. So my solution is to run a 'fsutil fsinfo drives' before triggering the net use, but want to use perl to decipher the available drive letter and looking for some wisdom on how best to do this.
my subprogram looks something like this, but I'm working to extend it for the above purpose.
sub copyDat {
my $file = basename($_[0]);
my $path = dirname($_[0]);
#$path .= "\\"; #trailing slash was needed for xcopy, but xcopy no
+t as reliable as robocopy for full automation with better logging.
print "\n File: $file \n\n";
print "\n Dirname: $path \n\n";
chomp $_[1];
my $map = $_[1];
my $map = $1 if($map=~/(.*)\\$/); #trailing slash not needed for r
+obocopy, but not sure if it's as picky, but it definately needs a map
+ping and not a unc path to work.
print "\nnet use $map && ROBOCOPY \"$path\" \"$map\" $file /B && n
+et use $map /delete\n\n"; #I'll add some more flags to robocopy to j
+azz it up but want to get this sequence to work first.
open TASK, "net use $map && ROBOCOPY \"$path\" \"$map\" $file /B &
+& net use $map /delete 2>&1|" or die "cannot pushd $_[1]";
while (<TASK>)
{
print;
#chomp;
#chop;
#return $_;
}
}
Again, if I try to robocopy using unc path I get the following error:
ERROR 5 (0x00000005) Getting File System Type of Destination
Access is denied.
This is pretty well documented on google too, maybe it's something with 2012, who knows, but all I know is I want to use robocopy and that I need to map the drive first to an available drive letter which won't be known until runtime.
Thanks much perlmonks, if anyone's up for the challenge thanks, otherwise I'll post what I decided to write as soon as I've figured out how to get perl to pull a drive letter not in the list windows command 'fsutil fsinfo drives' returns. I'm sure there's a quick and simple solution I didn't want to reinvent the wheel.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.