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