newbie help

Discussion in 'Perl' started by 'Captain' Kirk DeHaan, Apr 8, 2004.

  1. 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
     
    'Captain' Kirk DeHaan, Apr 8, 2004
    #1
    1. Advertising

  2. 'Captain' Kirk DeHaan wrote:
    > "@D:\Batch Files\StormC.bks" /f "S:\Backups\$newname" /v:yes /r:yes';


    Try:

    "S:\\Backups\\$newname"

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Apr 8, 2004
    #2
    1. Advertising

  3. Gunnar Hjalmarsson wrote:
    > 'Captain' Kirk DeHaan wrote:
    >> "@D:\Batch Files\StormC.bks" /f "S:\Backups\$newname" /v:yes /r:yes';

    >
    > 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.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Apr 8, 2004
    #3
  4. On Thu, 08 Apr 2004 16:52:17 GMT, Gunnar Hjalmarsson
    <> wrote:

    >Gunnar Hjalmarsson wrote:
    >> 'Captain' Kirk DeHaan wrote:
    >>> "@D:\Batch Files\StormC.bks" /f "S:\Backups\$newname" /v:yes /r:yes';

    >>
    >> 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.


    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
     
    'Captain' Kirk DeHaan, Apr 8, 2004
    #4
  5. 'Captain' Kirk DeHaan

    Joe Smith Guest

    'Captain' Kirk DeHaan wrote:

    > $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
     
    Joe Smith, Apr 8, 2004
    #5
  6. On Thu, 08 Apr 2004 19:42:42 GMT, Joe Smith <>
    wrote:

    >'Captain' Kirk DeHaan wrote:
    >
    >> $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
     
    'Captain' Kirk DeHaan, Apr 8, 2004
    #6
  7. On Thu, 08 Apr 2004 19:42:42 GMT, Joe Smith <>
    wrote:

    >'Captain' Kirk DeHaan wrote:
    >
    >> $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
     
    'Captain' Kirk DeHaan, Apr 8, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Bond
    Replies:
    0
    Views:
    541
    James Bond
    Aug 3, 2004
  2. Id0x
    Replies:
    4
    Views:
    1,209
    Erik Max Francis
    Jul 21, 2003
  3. JohnE

    newbie with newbie questions

    JohnE, Aug 17, 2009, in forum: ASP .Net
    Replies:
    3
    Views:
    522
    Gregory A. Beamer
    Aug 17, 2009
  4. LeTubs
    Replies:
    6
    Views:
    130
    Tad McClellan
    Jan 25, 2004
  5. Replies:
    56
    Views:
    747
    alex23
    Dec 27, 2012
Loading...

Share This Page