0

I have a batch file that's only 3 lines long.

What it does is simple:

type C:\data\file.bak >> echo "" >> file.log.bak

cscript "C:\data\Move filesA.vbs"
cscript "C:\data\Move filesB.vbs"

Basically all it does is take that file.bak and append it to the file.log.bak. They are just plain text files

The cscripts take the file.bak and moves it to a server location.

the type C:\data\file.bak >> echo "" >> file.log.bak was just added a few hours ago. The script runs every 15 minutes

When ran from a user (Double clicking the .bat file), it runs fine and copies the file to the file.log.bak with no problems

When run from the task, it doesn't execute the type C:\data\file.bak >> echo "" >> file.log.bak line, but executes the cscripts

My only guess would be that windows has a cached version of the batch file and it's not running the new batch file.

Is there any hint as to why it's not running the type C:\data\file.bak >> echo "" >> file.log.bak line when running from a scheduled task?

9
  • type C:\data\file.bak >> echo "" >> file.log.bak is an invalid command. What exactly are you trying to accomplish with this command? – I say Reinstate Monica May 11 '18 at 21:28
  • add the line to the file, but add a end line character first. It works when you run it manually (double click) – Chad K May 11 '18 at 22:08
  • do you have better success if you break that line of code into two lines, e.g. echo >> and then type...? – I say Reinstate Monica May 11 '18 at 22:23
  • Just did that, no success. I'm going to try and unschedule and schedule it again. I changed echo "" to echo. . It gives me all the same results but doesn't work from a scheduled task – Chad K May 11 '18 at 22:31
  • does the user account configured to run the task have sufficient NTFS permissions to the files? Try running task with highest privileges. – I say Reinstate Monica May 11 '18 at 22:34
0

Make sure you have the scheduled task running in a directory.

When using relative file paths, it will not work when ran from a different directory. Microsoft has included a feature that takes the command and runs it elsewhere, not where the file is located.

Double click on the scheduled task (or hit properties), go to Actions tab, then edit the action(s). From there you will see a popup with a 'Start in (optional)' field. Put the directory that the script is in (or what directory you want it to run in)

Popup to modify Start in directory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.