Perl execute SQLCMD with variables

0

I need to pass variables to the SQLCMD command. I have the following script:

#! /usr/bin/perl 
use strict;
use POSIX qw(strftime);
use Config::IniFiles;
my $TODAY = strftime "%Y%m%d", localtime;
my $cfg = Config::IniFiles->new( -file => 'test.ini' );
my @db = $cfg->Sections;

for my $dbs (@db){
  my $IP=$cfg->val($dbs,'ip');
  my $PORT=$cfg->val($dbs,'port');
  my $USER=$cfg->val($dbs,'user');
  my $PASS=$cfg->val($dbs,'pass');
  my $DB=$cfg->val($dbs,'pass');
  my $MOTOR=$cfg->val($dbs,'motor');
  my $INSTANCIA=$cfg->val($dbs,'instancia');
  my $PATH=$cfg->val($dbs,'path');
  my $DUMP=$PATH . "Backup_Test_" . $TODAY . ".bak";
  'sqlcmd -S $IP,$PORT -U $USER -P $PASS -Q "BACKUP DATABASE [$DB] TO DISK='$DUMP'"}';
  if($? == 0){
    print "0\n";
  }
  else{
    print "Error\n";
  }
 }

How I do it so that the sqlcmd takes the values of these variables. I have tried several combinations but I still can not perform database backup and I get a 0 as a result, the command was executed well but the dump is not generated ...?.

    
asked by Félix 04.10.2016 в 17:11
source

1 answer

0

From what I see, this script reads the configuration from an external file, the 'test.ini' (in ini format, of course), so that's where you have to make the changes.

The ini format is very simple: sections that start like this:

[section]

followed by key pairs = value

More information on link

    
answered by 06.10.2016 в 23:58