raphael75 Posted March 31, 2014 Share Posted March 31, 2014 Here is our setup:Server A - Windows 2008 R2 PHP script on server A that copies filesDrive O: on computer B - Windows computer contains source filesDrive V: on computer C - Debian Linux computer target folderWe have the PHP script on server A that copies files from the mapped drive O: (on computer B) to the mapped drive V: (on computer C). The script works perfectly when run manually from the command line.However, when the same PHP script is run from Task Scheduler it can't see the folders on drive O:. I had it echo out is_readable and is_writable on the O: drive folders, and when run from CLI they both return 1 but when run from task scheduler they return 0. I also had both echo out get_current_user and they both return the same user.The scheduled task is set to the same user the CLI one is, and is set to run with highest privileges.The scheduled task calls a batch file that then calls the php file. This is the contents of the batch file:@echo offstart "" /b /separate php -f "d:\scripts\get_files.php"If I run the batch file manually the script works, so it definitely seems to be something with the scheduled task itself, but I can't figure out what. Any help would be greatly appreciated. Thank you! Quote Link to comment Share on other sites More sharing options...
dalecosp Posted March 31, 2014 Share Posted March 31, 2014 Environment, then? Things like PATH and Drive Mappings would be prime suspects. Quote Link to comment Share on other sites More sharing options...
raphael75 Posted March 31, 2014 Author Share Posted March 31, 2014 I did some more testing. In the batch file I put in: dir O:\path\to\files > dir.txt net use > net_use.txt When I run the batch file manually both dir.txt and net_use.txt look right. However, when I run the scheduled task, dir.txt is empty and net_use.txt shows "unavailable" for the status of each mapped drive on the computer. What would cause the status to be "unavailable"? Quote Link to comment Share on other sites More sharing options...
trq Posted March 31, 2014 Share Posted March 31, 2014 I would suggest that whatever user the scheduled task runs as does not have permission to see these drives. Quote Link to comment Share on other sites More sharing options...
kicken Posted March 31, 2014 Share Posted March 31, 2014 A little googling on windows task scheduler and mapped drives shows that drives are only mapped for interactive sessions, not background sessions used for running tasks. If the drives do not require different credentials to be accessed, you can simply use a UNC path rather than map the drives: copy('\\\\server\\path\\file.ext', '\\\\server2\\path\\file.ext'); Otherwise, you can map the drive from the script by calling out to the net use command first. Some potentially helpful reading: How to use Windows Task Scheduler to copy files from a server in another domain Quote Link to comment Share on other sites More sharing options...
raphael75 Posted April 1, 2014 Author Share Posted April 1, 2014 Great information, thank you all! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.