#!/usr/bin/perl # # bbSend.pl - bbftp interface for remote repository # use strict; use IO::Socket; use File::Basename; # get command line args our $dest_repos = $ARGV[2]; our $source_orig = $ARGV[3]; our $local_source = $ARGV[4]; our $remote_path = $ARGV[5]; our $remote_dest = $ARGV[6]; # set global variables our $push_data = 1; our $parse_error = 0; our $bbftp_tmp_list = "/tmp/bbftp.tmp.ctrl.$$"; our $user_account; our $remote_dest; our $extra_param; # parameters for model C our $C_default_host = "datagw.virgo.infn.it"; our $C_user_account = "virgodata"; our $C_extra_param = "-s"; # parameters for model B our $B_default_host = "virgo-gateway-2.cnaf.infn.it"; our $B_user_account = "virgodata"; our $B_extra_param = "-w 21000"; # parameters for model L our $L_default_host = "ccbbftp.in2p3.fr"; our $L_user_account = "virgdata"; our $L_extra_param = "-s"; our $L_opt_1 = "setoption remoterfio"; our $L_opt_2 = "setremotecos 32"; our $L_opt_3 = "setbuffersize 8192"; our $L_opt_4 = "setrecvwinsize 8192"; our $L_opt_5 = "setsendwinsize 8192"; # check argv[0] if($ARGV[0] eq "-g") { $push_data = 0; } # check argv[1] if($ARGV[1] ne "-m") { $parse_error = 1; } # check $dest_repos if(($dest_repos eq "B") or ($dest_repos eq "L") or ($dest_repos eq "C")) { # do nothing } else { $parse_error = 1; } # check $source_orig if(($source_orig eq "-d") or ($source_orig eq "-l")) { # do nothing } else { $parse_error = 1; } # check $local_source and $remote_path if(($local_source eq "") or ($remote_path eq "")) { $parse_error = 1; } # check if local_soruce exist if($source_orig eq "-d") { if(-d $local_source) { # do nothing } else { print("error: directory $local_source not found\n"); $parse_error = 1; } } if($source_orig eq "-l") { if(-e $local_source) { # do nothing } else { print("error: file $local_source not found\n"); $parse_error = 1; } } # check for errors else continue if($parse_error == 1) { print("please use\n"); print(" bbSend.pl -p/-g -m -d [remote_host]\n"); print(" bbSend.pl -p/-g -m -l [remote_host]\n"); print(" where -p(ush) -g(et) and is B(ologna), C(ascina) or L(yon)\n\n"); exit(-1); } else { # set model values if($remote_dest eq "") { if($dest_repos eq "B") { $remote_dest = $B_default_host; $user_account = $B_user_account; $extra_param = $B_extra_param; } if($dest_repos eq "L") { $remote_dest = $L_default_host; $user_account = $L_user_account; $extra_param = $L_extra_param; } if($dest_repos eq "C") { $remote_dest = $C_default_host; $user_account = $C_user_account; $extra_param = $C_extra_param; } } print("set destination host to: $remote_dest\n"); print("set bbftp file list to: $bbftp_tmp_list\n"); # build bbftp cmd file open(BBFTP_CMD, ">$bbftp_tmp_list"); if($dest_repos eq "L") { print(BBFTP_CMD "$L_opt_1\n"); print(BBFTP_CMD "$L_opt_2\n"); print(BBFTP_CMD "$L_opt_3\n"); print(BBFTP_CMD "$L_opt_4\n"); print(BBFTP_CMD "$L_opt_5\n"); } my @array_file_list; # get the file list : directory if($source_orig eq "-d") { open(LS_OUT, "ls $local_source/* |"); @array_file_list = ; close(LS_OUT); } # get the file list : file if($source_orig eq "-l") { open(FILE_LIST, "<$local_source"); @array_file_list = ; close(FILE_LIST); } # insert file into transfer list my $counter = 0; while($counter < scalar(@array_file_list)) { chop($array_file_list[$counter]); if(length($array_file_list[$counter]) > 1) { my $file_basename = &basename($array_file_list[$counter]); if($push_data eq "1") { print(BBFTP_CMD "put $array_file_list[$counter] $remote_path/$file_basename\n"); } else { print(BBFTP_CMD "get $array_file_list[$counter] $remote_path/$file_basename\n"); } } $counter++; } close(BBFTP_CMD); # start bbftp file transfert system("bbftp -p 6 -u $user_account $extra_param -i $bbftp_tmp_list $remote_dest"); # check the bbftp output #open(BB_OUT, "cat $bbftp_tmp_list.res | grep put | grep OK | awk '{print $2}' | sort |"); #my @array_success = ; #close(BB_OUT); # check for errors #if(scalar(@array_success) == scalar(@array_file_list)) { # print("Parsing bbftp log ... all files successfully sent!\n"); #} else { # #} # remove /tmp files #unlink("$bbftp_tmp_list"); #unlink("$bbftp_tmp_list.res"); } exit(0);