diff options
author | Stig Thormodsrud <stig@vyatta.com> | 2010-11-02 18:32:25 -0700 |
---|---|---|
committer | Stig Thormodsrud <stig@vyatta.com> | 2010-11-02 18:32:25 -0700 |
commit | 493aa2868fa552d4bd397bbe5dc650f861aabe82 (patch) | |
tree | 6e8aaad369b9261d2622ea4338b1c1703a9dd48e /scripts/vyatta-commit-push.pl | |
parent | dacd9cc93d50902db729bea56b1fe8d3acd08e5b (diff) | |
download | vyatta-config-mgmt-493aa2868fa552d4bd397bbe5dc650f861aabe82.tar.gz vyatta-config-mgmt-493aa2868fa552d4bd397bbe5dc650f861aabe82.zip |
Convert perl system call to use WWW::Curl module
Diffstat (limited to 'scripts/vyatta-commit-push.pl')
-rwxr-xr-x | scripts/vyatta-commit-push.pl | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/scripts/vyatta-commit-push.pl b/scripts/vyatta-commit-push.pl index 2cbd887..da6c29e 100755 --- a/scripts/vyatta-commit-push.pl +++ b/scripts/vyatta-commit-push.pl @@ -36,6 +36,7 @@ use Vyatta::Config; use POSIX; use File::Basename; use URI; +use WWW::Curl::Easy; my $debug = 0; @@ -52,7 +53,7 @@ if (scalar(@uris) < 1) { my $upload_file = '/opt/vyatta/etc/config/config.boot'; my $timestamp = strftime("_%Y%m%d_%H%M%S", localtime); -my $same_file = basename($upload_file) . $timestamp; +my $save_file = basename($upload_file) . $timestamp; print "Archiving config...\n"; foreach my $uri (@uris) { @@ -68,15 +69,19 @@ foreach my $uri (@uris) { } $remote .= "$scheme://$host"; $remote .= "$path" if defined $path; - print " $remote "; - my $cmd = "curl -s -T $upload_file $uri/$same_file"; - print "cmd [$cmd]\n" if $debug; - my $rc = system($cmd); - if ($rc eq 0) { - print " OK\n"; + open(my $FILE, '<', $upload_file) or die "Error: read $!"; + my $curl = new WWW::Curl::Easy; + $curl->setopt(CURLOPT_NOPROGRESS, 1); + $curl->setopt(CURLOPT_URL, "$uri/$save_file"); + $curl->setopt(CURLOPT_UPLOAD, 1); + $curl->setopt(CURLOPT_INFILE, $FILE); + $curl->setopt(CURLOPT_VERBOSE, $debug); + my $retcode = $curl->perform; + if ($retcode == 0) { + print "Ok\n"; } else { - print " failed\n"; + print "Failed: " . $curl->strerror($retcode) . "\n"; } } |