0

I have a batch script to rename and upload a file to some other server and it is scheduled in Windows Task Scheduler.

When it was scheduled with my own id and password then the file was getting uploaded with a proper name, which is Performance_Report_20160715.csv.

But when I changed that to a non-user account and password (A no password expiry account), it's getting uploaded with a strange name Performance_Report_on.15.csv

Kindly help me clarify why "_on" is getting appended instead of "current_date", where no changes have been made to the script.

Batch Script

@echo off

for /F "tokens=1* delims= " %%A in ('date /T') do set CDATE=%%B
for /F "tokens=1,2 eol=/ delims=/ " %%A in ('date /T') do set mm=%%B
for /F "tokens=1,2 delims=/ eol=/" %%A in ('echo %CDATE%') do set dd=%%B
for /F "tokens=2,3 delims=/ " %%A in ('echo %CDATE%') do set yyyy=%%B
set mydate=%yyyy%%mm%%dd%

ping 127.0.0.1 -n 20 -w 60000 > nul

RENAME Performance_Report.csv Performance_Report_%mydate%.csv

del ftpcmd.dat

echo user username>> ftpcmd.dat
echo password>> ftpcmd.dat
echo BINARY>> ftpcmd.dat
echo put D:\Upload\Performance_Report_%mydate%.csv>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat 123.45.6.78>>PerformanceLog.txt
del ftpcmd.dat

MOVE "Performance_Report_%mydate%.csv" "D:\Upload\Performance_Archive\"
Sudipta Roy
  • 103
  • 1
  • 3
  • 11
  • Variable `CDATE` becomes empty, so `echo` sees no argument and returns the echo state `ECHO is on.`; I'm quite sure this is caused by the fact that `date /T` returns the date in a locale-dependent manner; the `for /F` options need to be adapted to the format for the script to work... hence I suggest to follow [this post](http://stackoverflow.com/a/203116)... – aschipfl Jul 19 '16 at 07:18
  • Thanks, the reffered post is helpful. It only differs from my requirement in the output format. It gives output in YYYY-MM-DD. – Sudipta Roy Jul 25 '16 at 09:30

1 Answers1

0

Probably date /t command is returning the date in a different format for the other user account causing the script to fail. Could you please check if the date /t returns the date in expected format for the other account?

If not, you can change it in Control Panel --> Region --> Date and Time formats --> Short date.

Also, please check if changing the script like this works the same in all machines/accounts,

@echo off

for /f %%x in ('wmic path win32_utctime get /format:list ^| findstr "="') do set %%x
set mydate=%Year%%Month%%Day%

ping 127.0.0.1 -n 20 -w 60000 > nul

RENAME Performance_Report.csv Performance_Report_%mydate%.csv

del ftpcmd.dat

echo user username>> ftpcmd.dat
echo password>> ftpcmd.dat
echo BINARY>> ftpcmd.dat
echo put D:\Upload\Performance_Report_%mydate%.csv>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat 123.45.6.78>>PerformanceLog.txt
del ftpcmd.dat

MOVE "Performance_Report_%mydate%.csv" "D:\Upload\Performance_Archive\"
  • I just now verified. Logging in from both accounts return the same output. **Tue 07/19/2016** – Sudipta Roy Jul 19 '16 at 06:43
  • When I execute the same script in my machine, I get value of `mydate` as `on.`, not the date. –  Jul 19 '16 at 06:54
  • So, the same script is giving different output. Can you please suggest the fix to rectify the issue? – Sudipta Roy Jul 19 '16 at 07:01
  • I've suggested an alternate script, please see if it works fine in all accounts. We may need to enhance it further to append a **0** if months and dates are in single digit. –  Jul 19 '16 at 07:16
  • Thanks @jnanthak. It is working. I will modify the script for the ZERO issue. – Sudipta Roy Jul 19 '16 at 08:21