newbie help

  • Thread starter 'Captain' Kirk DeHaan
  • Start date
C

'Captain' Kirk DeHaan

I am trying to automate a disk backup process using Windows NT
ntbackup. I want to have the date associated with the backup file
name. I am having trouble getting Perl to translate the file name in
the command I am trying to execute. Here is what I have.

$date = `udate +%m%d%y`;
$date =~ s/\n//;
$newname = "StormC $date.bkf";
print $newname;
exec 'C:\WINDOWS\SYSTEM32\ntbackup.exe', 'backup systemstate
"@D:\Batch Files\StormC.bks" /f "S:\Backups\$newname" /v:yes /r:yes';

If I run this $newname is printed as StormC 040804.bkf. This is what
I want considering this is posted on 040804. Ntbackup syntax requires
the double quotes around the various arguments in the command string.
The backup will start but the file name for the backup becomes
$newname. I have looked but cannot find how to get perl to preprocess
the variable before executing the backup command.

Where am I going wrong or what am I leaving out?



Kirk

"Moe, Larry, the cheese!", Curly
 
G

Gunnar Hjalmarsson

Gunnar said:
Try:

"S:\\Backups\\$newname"

Second thought: Don't.

Now I see that the string is surrounded by single-quotes. Replace
those with double-quotes, and at the same time escape (using \) both
all the \ characters and the double-quotes within the string.
 
C

'Captain' Kirk DeHaan

Second thought: Don't.

Now I see that the string is surrounded by single-quotes. Replace
those with double-quotes, and at the same time escape (using \) both
all the \ characters and the double-quotes within the string.

Thanks. Tried that and ntbackup aborted. I then realized that the @
needed escaped as well. It worked then.

I have a better understanding of Perl now. :)



Kirk

"Moe, Larry, the cheese!", Curly
 
J

Joe Smith

'Captain' Kirk DeHaan said:
$date = `udate +%m%d%y`;
$date =~ s/\n//;

That last line is usually written as
chomp $date;

It can be eliminated by not using backticks.
my ($day,$mon,$year) = (localtime)[3,4,5];
my $date = sprintf "%02d%02d%4d", $mon+1, $day, $year+1900;

-Joe
 
C

'Captain' Kirk DeHaan

'Captain' Kirk DeHaan said:
$date = `udate +%m%d%y`;
$date =~ s/\n//;

That last line is usually written as
chomp $date;

It can be eliminated by not using backticks.
my ($day,$mon,$year) = (localtime)[3,4,5];
my $date = sprintf "%02d%02d%4d", $mon+1, $day, $year+1900;

-Joe

Thanks, I will try them. Just getting started.



Kirk

"Moe, Larry, the cheese!", Curly
 
C

'Captain' Kirk DeHaan

'Captain' Kirk DeHaan said:
$date = `udate +%m%d%y`;
$date =~ s/\n//;

That last line is usually written as
chomp $date;

It can be eliminated by not using backticks.
my ($day,$mon,$year) = (localtime)[3,4,5];
my $date = sprintf "%02d%02d%4d", $mon+1, $day, $year+1900;

-Joe

And with a slight mod I get the format I wanted.

my $date = sprintf "%02d%02d%02d", $mon+1, $day, $year % 100;



Kirk

"Moe, Larry, the cheese!", Curly
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top