From 521acd4c79757036fd2630f0a84e334be6b70484 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 9 May 2009 23:54:58 +0000 Subject: [PATCH] move cdr-sftp_and_import script to FS/bin, add -p option, RT#4081 --- .../bin/freeside-cdr-sftp_and_import | 61 ++++++++++++++++------ 1 file changed, 46 insertions(+), 15 deletions(-) rename bin/cdr.sftp_and_import => FS/bin/freeside-cdr-sftp_and_import (66%) diff --git a/bin/cdr.sftp_and_import b/FS/bin/freeside-cdr-sftp_and_import similarity index 66% rename from bin/cdr.sftp_and_import rename to FS/bin/freeside-cdr-sftp_and_import index 79e743f39..5786774d2 100755 --- a/bin/cdr.sftp_and_import +++ b/FS/bin/freeside-cdr-sftp_and_import @@ -1,10 +1,4 @@ #!/usr/bin/perl -# -# Usage: -# cdr.sftp_and_import [ -e extension ] [ -d donefolder ] [ -v ] user format [sftpuser@]servername -# -# -e: file extension, defaults to .csv -# -d: if specified, moves files to the specified folder when done use strict; use Getopt::Std; @@ -16,13 +10,15 @@ use FS::cdr; # parse command line ### -use vars qw( $opt_e $opt_d $opt_v ); -getopts('e:d:v'); +use vars qw( $opt_p $opt_e $opt_d $opt_v ); +getopts('p:e:d:v'); $opt_e ||= 'csv'; #$opt_e = ".$opt_e" unless $opt_e =~ /^\./; $opt_e =~ s/^\.//; +$opt_p ||= ''; + my $user = shift or die &usage; adminsuidsetup $user; @@ -43,7 +39,7 @@ warn "Retreiving directory listing\n" if $opt_v; my $ls_sftp = sftp(); -my $ls = $ls_sftp->ls('.', wanted => qr/\.*$opt_e$/i ); +my $ls = $ls_sftp->ls('.', wanted => qr/^$opt_p.*\.$opt_e$/i ); ### # import each file @@ -62,15 +58,13 @@ foreach my $file ( @$ls ) { warn "Processing $filename\n" if $opt_v; my $error = FS::cdr::batch_import( { - 'file' => "$cachedir/$filename" + 'file' => "$cachedir/$filename", 'format' => $format, 'params' => { 'cdrbatch' => $filename, }, 'empty_ok' => 1, } ); die $error if $error; - close FILE; - if ( $opt_d ) { my $mv_sftp = sftp(); $mv_sftp->rename($filename, "$opt_d/$filename") @@ -81,10 +75,8 @@ foreach my $file ( @$ls ) { } -1; - ### -# sub +# subs ### sub usage { @@ -110,3 +102,42 @@ sub sftp { $sftp; } +=head1 NAME + +cdr.sftp_and_import - Download CDR files from a remote server via SFTP + +=head1 SYNOPSIS + + cdr.sftp_and_import [ -p prefix ] [ -e extension ] [ -d donefolder ] [ -v ] user format [sftpuser@]servername + +=head1 DESCRIPTION + +Command line tool to download CDR files from a remote server via SFTP and then +import them into the database. + +-p: file prefix, if specified + +-e: file extension, defaults to .csv + +-d: if specified, moves files to the specified folder when done + +-v: verbose + +user: freeside username + +format: CDR format name + +[sftpuser@]servername: remote server + +=head1 BUGS + +Only supports SFTP right now. + +=head1 SEE ALSO + +L + +=cut + +1; + -- 2.11.0