Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy on w2k3 from local to UNC/share fails 1

Status
Not open for further replies.

keithinsac

Programmer
May 28, 2008
5
US
Hello,

I'm having a problem with a script that uses the Perl::Copy mod to copy a file from the local host to a network share. From local to local the copy works just fine (ie c:\dir\file.txt to e:\dir\file.txt), but when copying from local to a UNC, it continues to fail. The UNC share is a win 2k3 server that currently has everyone full control share and NTFS permissions. The script is run by a windows service that is run under the local system account. I have been trying with both perl copy and additionally trying using the perl system command to use the OS's copy. Interactively (stub testing logged on) the script runs fine, but when a windows service kicks off the script it fails. Below is the code and following is the output. Please help....

Code:

print LOG "\n\n === Tripwire Integration Start ===";
my($tw_host) = "\\\\myserver\\Teamsite_Incoming\\";
my($ts_log_file) = $deploylistfile; --> defined earlier in the script and set to a valid file like "e:\\mylocaldir\\localfile.txt"

print LOG "\nTripwire Incoming Host: $tw_host";
print LOG "\nTeamsite Log File: $ts_log_file";
if (-f $ts_log_file) {
print LOG "\n - file exists: OK";
# strip the path off $ts_log_file and copy the file to new location
my($file) = basename($ts_log_file);
print LOG "\n - file: $file";
my($ext) = extension($ts_log_file);
print LOG "\n - extension: $ext";
print LOG "\n - from: $ts_log_file";
print LOG "\n - to: $tw_host";
if($ext eq "tmp") {
# PERL COPY ------------------------------------------------
$cpresult = copy($ts_log_file,$tw_host.$file);
print LOG "\n perl copy result: $?:$! | cpresult: $cpresult";
# ----------------------------------------------------------

# SYSTEM HOST COPY -----------------------------------------
my @comargs = ('COPY', $ts_log_file, $tw_host.$file);
$cpresult = system(@comargs);
print LOG "\n system @comargs result: $?:$! | cpresult: $cpresult";
# ----------------------------------------------------------
} else {
print LOG "file passed is not a TeamSite log file ('$ts_log_file')";
}
print LOG "\n === Tripwire Integration End ===\n\n";
Output:

=== Tripwire Integration Start ===
Tripwire Incoming Host: \\myserver\TeamSite_Incoming\
Teamsite Log File: e:\Interwoven\OpenDeployNG\tmp\wft_trip_stg_deploy_438540.tmp
- file exists: OK
- file: wft_trip_stg_deploy_438540.tmp
- extension: tmp
- from: e:\Interwoven\OpenDeployNG\tmp\wft_trip_stg_deploy_438540.tmp
- to: \\myserver\TeamSite_Incoming\
perl copy result: 0:No such file or directory | cpresult:
system COPY e:\Interwoven\OpenDeployNG\tmp\wft_trip_stg_deploy_438540.tmp \\myserver\TeamSite_Incoming\wft_trip_stg_deploy_438540.tmp result: 256:No such file or directory | cpresult: 256
=== Tripwire Integration End ===

I don't understand why the error is reported as 'No such file or directory' when interactively, it works just fine. Shouldn't I get a permission error...? Any help is greatly appreciated.

Thank you, Keith

 
Possibly you should map to that share first?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Thanks for the feedback travs69, but I really want to get this to work via perl copy. When run as a server process from a Windows service, the only way to drive map is by executing another perl system(args) command with 'net use', but there is no logged on user as the windows service (local system) is the executor. Additionally, that would require a clear text password set in my script. Any other ideas?

Thank you for replying, all help is appreciated.

 
If it is an open share you don't need to supply a password. I have seen many others having the same problem (UNC path doesn't work.. or doesn't work the first time) and i don't recall any other solutions working.

I think i would do the system call to map the drive/delete the drive and use perl's file copy. I think it is also wise to not map it to a drive letter.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
I changed the script as suggested and now I get a different error. Any idea?

Code:
my @comargs = ("net use f: \\\\myserver\\teamsite_incoming\\");
$res = system(@comargs);
print LOG "\n system @comargs result: $?:$! | res: $res";

$cpresult = copy($ts_log_file,"f:\\".$file);
print LOG "\n perl copy result: $?:$! | cpresult: $cpresult";

my @comargs = ('net use f: /delete');
$res = system(@comargs);
print LOG "\n system @comargs result: $?:$! | res: $res";

Output:
system net use f: \\myserver\teamsite_incoming\ result: 512:Bad file descriptor | res: 512
perl copy result: 512:No such file or directory | cpresult:
system net use f: /delete result: 512:No such file or directory | res: 512 - copy of e:\OpenDeployNG\tmp\wft_trip_stg_deploy_440437.tmp

Again, thank you very much, Keith
 
You don't have enough \'s to do it the way your are. Try this

$source = '\\\\127.0.0.1\\Movies';

$res = qx~net use $source~;
$res1 = qx~net use $source /delete~;

print "$res \n\n $res1\n";

Notice single quotes around all the info. qx is the same as back ticks which is like system but different.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
that's bad code to (well it's work but won't give you results like I expected)
Code:
$source = '\\\\127.0.0.1\\Movies';

@res = qx~net use $source~;
@res1 = qx~net use $source /delete~;

print "@res \n\n @res1\n";

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Hey there travs69,

I wanted to say a big Thank You for all your help. Drive mapping helped clueing in on what the issue was and provided a more detailed message when erroring out. The real issue was that the Windows service that kicks off the Perl script runs under 'Local System'. That system (machine) account by default (and design) does not have permissions from server to server as it has no SID. The server admin is not interested in configuring the service to run as an account, so the only other way is to provide credentials. The only way I know of is via clear text in the script. For future reference, is there any other way to establish the security context needed without clear text?

As an alternative solution instead I've just decided to write my own Windows service, have it run under the approp account, and perform the file copy independent of the script.

Oh, also, in the previous post the "512:Bad file descriptor" was coming from the "$!" portion of the " result: $?:$!". When removed, the copy performed as it should. Why's that...?

Thanks again, Keith
 
Adding or removing $! from a print statement should not have affected anything. I got the same error when only using the same slashes as you in double quotes vs single.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
You could pass the password to the script via the cron/at (whatever) but that's just moving it from one clear text place to another. You could obfusicate the whole script (using Acme::Bleach or any other of those types of scripts) but that really only hides the password, it doesn't remove the fact that a smart person can find it.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
True, too true. Windows has Task Scheduler which is similar to cron for W2k3 (vs At for W2k) and has a command line tool and API (schtasks.exe). The only problem is that if run from the command interface and the task has saved credentials, the saved credentials aren't used unless a local Admin is running the task and have to be provided on call.

Thanks again for your help. Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top