• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 921
  • Last Modified:

Win2003 Scheduled task command line expansion bug?

I have a nighty NT Backup task (on Windows Werver 2003) like this

ntbackup.exe backup  /n "Nightly Backup %DATE%"  /d "Set created %DATE% at %TIME%"

(irrelavant stuff removed)

The %DATE% and %TIME% do expand, but they don't expand correctly, I get
Media name: "Nightly Backup 4/20/2006ATE%"
and
Backup description: "Set created 4/20/2006ATE% at 3:30 AMIME%"

Thus the "ATE%" portion of "%DATE%" and the "IME%" portion of "%TIME%" don't get replaced.

Am I doing something wrong or is this a bug?
0
JohnBPrice
Asked:
JohnBPrice
  • 6
  • 5
  • 3
1 Solution
 
WelkinMazeCommented:
Hi,

You can try this one:
echo "Nightly Backup %DATE%" "Set created %DATE% at %TIME%"

If it is not correctly printed then you are doing everything right and it is some bug.
0
 
JohnBPriceAuthor Commented:
It does correctly replace from command prompt (same machine, same user account the scheduled task runs under).  Furthermore, it replaces differently, %DATE% includes the day abbreviation, and time is hh:mm:ss.ss.  Makes me suspect there might be some environment variable that doesn't set for scheduler?
0
 
WelkinMazeCommented:
Hm, really strange.
Maybe you can try to set "Nightly Backup %DATE%"  and "Set created %DATE% at %TIME%" preliminary to some other variables and to use these variables when executing the command.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
boris711Commented:
I'm not trying to be a wiseguy, but what happens if you shorten the variable references to %D and %T? While what you're getting isn't expected behavior, it would seem that the variables are still being interpretted correctly adding the unnecessary reference parts back into the text line.

0
 
WelkinMazeCommented:
boris711, I've thought about the same but %D and %T do not work at the command line in normal circumstances. Maybe there are some specific variables for the backup application. Anyway, it will be fine if this works. :)
0
 
boris711Commented:
Another thought. You can check the currently configured system variables by typing "set" at a command-line, it is possible that "D" and "T" have been configured as variables representing the Date and Time, respectively. Though that doesn't explain why the trailing "%" sign is still left in the string.
0
 
JohnBPriceAuthor Commented:
Boris, expansion requires an opening and closing "%", e.g. %Date%  will not expand the %D portion.  %Date% and %Time% are built-in variables, they are not defined.
0
 
boris711Commented:
I understand that %DATE% and %TIME% are built-in system environment variables. Was wondering if "D" and "T" had possibly been defined as variables equivalent to the above respective values.

My assumption is that you're using Task Scheduler. How are you calling "ntbackup" with a script, batch file or passed as a command-line?  

0
 
JohnBPriceAuthor Commented:
OK, I give.  If I schedule this task  >C:\WINDOWS\system32\cmd.exe /C "echo %DATE% t: %TIME%>C:\test.txt"
the results are  Thu 04/20/2006 t: 10:36:00.05", i.e. it works fine

If I run this >ntbackup backup "C:\test.txt" /F "C:\Test.bkp" /D "bk %DATE%"
the result is >Backup description: "bk Thu 04/20/2006", it also works fine,

but if I SCHEDULE the same >ntbackup backup "C:\test.txt" /F "C:\Test.bkp" /D "bk %DATE%",
the result is >Backup description: "bk 4/20/2006ATE%"
0
 
JohnBPriceAuthor Commented:
Boris, it is possible that NTBackup is doing the expansion instead of the shell, so maybe %D has some merit, testing now.

I am indeed using task scheduler, and I use the "ntbackup blah blah" as the "Run:".  It just occurred that I might be able to do cmd.exe /C "ntbackup .....", though I might get fouled with embedded quotes.  I'll try that too.
0
 
JohnBPriceAuthor Commented:
Bingo Boris!  You are da'man.  It seems that NTBackup simply expands %D, I scheduled:

ntbackup backup "C:\test.txt" /J "jb %DATE% " /F "C:\Test.bkp" /D "bk %D"

and got Backup description: "bk 4/20/2006"

Note that the job name didn't expand at all, the job was still "JB %DATE%"

go figure.
0
 
boris711Commented:
Have you tried encapsulating your command-line in a batch file and then calling the batch file from Task Scheduler?

Or VBScript is another option.

It is possible there is a bug in passing the switches thru Task Scheduler.
0
 
JohnBPriceAuthor Commented:
I tried the cmd.exe trick with

C:\WINDOWS\system32\cmd.exe /C "ntbackup backup ""C:\test.txt"" /J ""jb %DATE% "" /F ""C:\Test.bkp"" /D ""bk %DATE%"""

but got "Expecting more command line parameters." in the backup log.  I don't know how to escape quotes in shell commands.


>>Have you tried encapsulating your command-line in a batch file and then calling the batch file from Task Scheduler?
That would be a good third option too.  

Thanks for your help.
0
 
boris711Commented:
You're welcome and Good Luck!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 6
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now