我需要从Perl将变量传递给sqlcmd
。
这是剧本。
#! /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";
}
}
我将变量传递给sqlcmd
,但我得到的结果是零,我没有得到转储。