# Batch file success at CL but fails when scheduled task

#### What is the problem you are having with rclone?

I have a network shared drive mapped to a windows PC. I'm using RClone copy to back up all of the directories at the root of that share and their contents to Box. My RClone command is included in a batch file. When I execute the batch file from the command line, it runs as expected; however, when the batch file is executed via Scheduled Task, it fails (3 times) with "error reading source directory: directory not found". Batch file below.


v1.56.1

Box

#### The command you were trying to run (eg rclone copy /tmp remote:tmp)

Batch file contents:
DEL C:\Users\usernm\Documents\Scripts\log.txt
rclone copy Z:\ -P -vv --log-file C:\Users\usernm\Documents\Scripts\log.txt boxconfig:/ExO/LabBackups/usr-nas/usrlab


#### The rclone config contents with secrets removed.

[boxconfig]
type = box
box_sub_type = user
token = {"access_token":"accessremoved","token_type":"bearer","refresh_token":"refreshremoved","expiry":"2021-09-30T10:21:46.600906-07:00"}


#### A log from the command with the -vv flag

2021/09/29 23:00:06 DEBUG : rclone: Version "v1.56.1" starting with parameters ["rclone" "copy" "Z:\\" "-P" "-vv" "--log-file" "C:\\Users\\usernm\\Documents\\Scripts\\log.txt" "boxconfig:/ExO/LabBackups/usr-nas/usrlab"]
2021/09/29 23:00:06 DEBUG : Creating backend with remote "Z:\\"
2021/09/29 23:00:06 DEBUG : Using config file from "C:\\Users\\usernm\\.config\\rclone\\rclone.conf"
2021/09/29 23:00:06 DEBUG : fs cache: renaming cache item "Z:\\" to be canonical "//?/Z:/"
2021/09/29 23:00:06 DEBUG : Creating backend with remote "boxconfig:/ExO/LabBackups/usr-nas/usrlab"
2021/09/29 23:00:06 DEBUG : box root 'ExO/LabBackups/usr-nas/usrlab': Token expired but no uploads in progress - doing nothing
2021/09/29 23:00:06 DEBUG : boxconfig: Loaded invalid token from config file - ignoring
2021/09/29 23:00:07 DEBUG : Saving config "token" in section "boxconfig" of the config file
2021/09/29 23:00:07 DEBUG : Keeping previous permissions for config file: -rw-rw-rw-
2021/09/29 23:00:07 DEBUG : boxconfig: Saved new token in config file
2021/09/29 23:00:10 DEBUG : fs cache: renaming cache item "boxconfig:/ExO/LabBackups/usr-nas/usrlab" to be canonical "boxconfig:ExO/LabBackups/usr-nas/usrlab"
2021/09/29 23:00:11 ERROR : Local file system at //?/Z:/: error reading source root directory: directory not found
2021/09/29 23:00:11 DEBUG : box root 'ExO/LabBackups/usr-nas/usrlab': Waiting for checks to finish
2021/09/29 23:00:11 DEBUG : box root 'ExO/LabBackups/usr-nas/usrlab': Waiting for transfers to finish
2021/09/29 23:00:11 ERROR : Attempt 1/3 failed with 1 errors and: directory not found
2021/09/29 23:00:12 ERROR : Local file system at //?/Z:/: error reading source root directory: directory not found
2021/09/29 23:00:12 DEBUG : box root 'ExO/LabBackups/usr-nas/usrlab': Waiting for checks to finish
2021/09/29 23:00:12 DEBUG : box root 'ExO/LabBackups/usr-nas/usrlab': Waiting for transfers to finish
2021/09/29 23:00:12 ERROR : Attempt 2/3 failed with 1 errors and: directory not found
2021/09/29 23:00:13 ERROR : Local file system at //?/Z:/: error reading source root directory: directory not found
2021/09/29 23:00:13 DEBUG : box root 'ExO/LabBackups/usr-nas/usrlab': Waiting for checks to finish
2021/09/29 23:00:13 DEBUG : box root 'ExO/LabBackups/usr-nas/usrlab': Waiting for transfers to finish
2021/09/29 23:00:13 ERROR : Attempt 3/3 failed with 1 errors and: directory not found
2021/09/29 23:00:13 INFO  :
Transferred:   	          0 / 0 Byte, -, 0 Byte/s, ETA -
Errors:                 1 (retrying may help)
Elapsed time:         7.0s

2021/09/29 23:00:13 DEBUG : 7 go routines active



Can anyone suggest why the batch file will run without error from the command line but fail as a scheduled task?

the username that is running the task needs to be able to see the z: drive.

fwiw, i use the direct \\server\share, instead of a drive letter, z:

Thank you for your input and suggestion. This configuration works well in other cases - if I reference a subfolder. By that I mean if instead of "rclone copy Z:\ ..." I use "rclone copy Z:\subfolder\ ..." it works.
I have tried your suggestion of using \\server\share, but I have the same results as referencing the mapped 'Z' drive.
I'll continue to work this from other angles, but if anyone has any other suggestions or can provide a reason why trying to copy directly from the root of a mapped drive simply doesn't work, I'd like to hear them.
Thanks!

need to figure out is this is a rclone issue or a windows issue

as a test, i would change the script to this

dir z:\ > c:\path\to\folder\dir.txt
rclone lsd z:\ >> c:\path\to\folder\dir.txt


Thank you for your help! Sorry it took me so long to get back around to this. Your input and recommendations led me to find the problem was what you described. To correct it and maintain some amount of security I've created a Python script that the batch file executes right before the rclone command is executed. Basically, the Python decrypts a username and password then executes a 'net use' to mount the share on the expected drive letter.
Problem solved!

glad i could help solve the problem.

i do the same thing, have a python script that: