Index: palm/trunk/SCRIPTS/batch_scp
===================================================================
--- palm/trunk/SCRIPTS/batch_scp	(revision 693)
+++ palm/trunk/SCRIPTS/batch_scp	(revision 1090)
@@ -1,52 +1,54 @@
 #! /bin/ksh
-# batch_scp - Shellskript         Version:  @(#)batch_scp 1.0a     25/10/05
+
+# batch_scp - script for automatic file/directory transfer using scp
+
+#--------------------------------------------------------------------------------#
+# This file is part of PALM.
+#
+# PALM is free software: you can redistribute it and/or modify it under the terms
+# of the GNU General Public License as published by the Free Software Foundation,
+# either version 3 of the License, or (at your option) any later version.
+#
+# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# PALM. If not, see <http://www.gnu.org/licenses/>.
+#
+# Copyright 1997-2012  Leibniz University Hannover
+#--------------------------------------------------------------------------------#
+#
+# Current revisions:
+# ------------------
+# code put under GPL (PALM 3.9) 
+# adjustments for Kyushu-University computing center (lckyut)
+# old changelog messages removed
+#
+# Former revisions:
+# -----------------
 # $Id$
-
-     # Prozedur zum automatischen Transfer von Dateien mittels scp
-     #
-     # batch_scp hat 4 Argumente:
-     #         $1 = IP-Adresse des Zielrechners
-     #         $2 = zu uebertragende Datei
-     #         $3 = Verzeichnis, in das kopiert werden soll
-     #         $4 = Dateiname der Zieldatei
-
-
-     #                 ACHTUNG!!!!!!!!
-     #
-     # batch_scp hat noch folgenden grossen Mangel: wenn die Verzeichnisse
-     # auf den jeweiligen Remote-Rechnern aeltere Dateien beinhalten,
-     # die beim "ls -al" eine Jahreszahl und keine Uhrzeit (aa:bb) liefern,
-     # dann kann batch_scp die Dateinamen nicht ueberpruefen und findet
-     # z.B. bei -g die entsprechende Datei nicht!
-     #
-     #
-
-
-     # letzte Aenderung:
-     # 29/11/01 - Siggi - Entwicklungsbeginn
-     # 04/01/02 - Siggi - Version 1.0 funktionsfaehig
-     # 15/02/02 - Siggi - Verzeichnis-Listing umgestellt von "ls -al" auf "ls -1"
-     # 30/05/02 - Siggi - Abbruch mit exit 1 bei scp- oder ssh-Fehler
-     # 12/06/02 - Siggi - Version 1.0a, parent directories are also created, if
-     #                    directory on remote host does not exist
-     # 18/09/02 - Siggi - Fehlerabfragen korrigiert (waren wegen Klammerung
-     #                    unwirksam)
-     # 12/03/03 - Siggi - errfile and filelist are not stored in /tmp any more
-     #                    errors in execution of ssh does not lead
-     #                    to an abort on the NEC-system at DKRZ
-     # 01/04/03 - Siggi - small error concerning creation of catalogs removed
-     # 23/01/04 - Siggi - additional test output for scp on hurrikan
-     # 02/12/04 - Siggi - additional check of file size on remote host after scp.
-     #                    If the file sizes on local and remote host are equal,
-     #                    the scp exit status is ignored
-     # 03/12/04 - Siggi - additional checks of ssh actions independent of the
-     #                    ssh exit status
-     # 11/03/05 - Siggi - arguments are output in case of error exit
-     # 25/10/05 - Siggi - put of catalogs realized
-     # 27/04/09 - Marcus- use option -p for all scp calls
-     # 08/03/11 - Siggi - adjustments for ibmkisti: this machine allows
-     #                    outgoing ssh/scp connections only from the
-     #                    interactive nodes (gaiad). All ssh/scp traffic is
-     #                    done via this interactive node.
+#
+# 08/03/11 - Siggi - adjustments for ibmkisti: this machine allows
+#                    outgoing ssh/scp connections only from the
+#                    interactive nodes (gaiad). All ssh/scp traffic is
+#                    done via this interactive node.
+# 04/01/02 - Siggi - first version finished
+# 29/11/01 - Siggi - script development started
+#
+#--------------------------------------------------------------------------------#
+# batch_scp - script for automatic file/directory transfers using scp
+#
+# batch_scp has 4 arguments:
+#               $1 = IP-addres of remote (target) machine
+#               $2 = file to be transferred
+#               $3 = directory of remote machine, where file should be copied to
+#               $4 = filename that file should be given on remote machine
+#
+# ATTENTION: problems might occur if directories on remote machine include very
+#            old files for which "ls -al" does give "year" as modification
+#            time instead of "hh:mm". In such a case, batch_scp cannot check the
+#            filename and may not find the file (e.g. if option -g is used).
+#--------------------------------------------------------------------------------#
 
 
@@ -60,5 +62,5 @@
  check=false
  delete=false
- errfile=ftpcopy.errfile.$random
+ errfile=batch_scp.errfile.$random
  filelist=filelist.$random
  get=false
@@ -81,5 +83,6 @@
  trap 'if [[ $locat != normal ]]
        then
-          cat $filelist $errfile
+          [[ -f "$filelist" ]]  &&  cat $filelist
+          [[ -f "$errfile"  ]]  &&  cat $errfile
           rm -rf $filelist $errfile
           printf " +++ BATCH_SCP terminated \n"
@@ -296,5 +299,5 @@
     ssh $local_user@gaiad "ssh $1 -l $remote_user \"cd $3; ls -1; echo '*** list complete'\" "  > $filelist  2>&1
  else
-    ssh $1 -l $remote_user "cd $3; ls -1; echo '*** list complete'" > $filelist  2>&1
+    ssh -p 22 $1 -l $remote_user "cd $3; ls -1; echo '*** list complete'" > $filelist  2>&1
  fi
  ssh_status=$?
@@ -506,5 +509,5 @@
        ssh $local_user@gaiad "ssh $1 -l $remote_user \"cd $3\" " > $filelist
     else
-       ssh $1 -l $remote_user "cd $3" > $filelist
+       ssh $1 -p 22 -l $remote_user "cd $3" > $filelist
     fi
     if [[ $? != 0 ]]
@@ -569,7 +572,7 @@
              if [[ $catalog_copy = false ]]
              then
-                scp -p $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
+                scp -P 22 -p $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
              else
-                scp -p -r $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
+                scp -P 22 -p -r $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
              fi
           fi
@@ -587,5 +590,5 @@
                 remote_size=`ssh $local_user@gaiad "ssh $1 -l $remote_user \"ls -al $catalog_name$4$zyklusnr\" "`
              else
-                remote_size=`ssh $1 -l $remote_user "ls -al $catalog_name$4$zyklusnr"`
+                remote_size=`ssh $1 -p 22 -l $remote_user "ls -al $catalog_name$4$zyklusnr"`
              fi
              remote_size=`echo $remote_size | cut -d" " -f5`
@@ -604,5 +607,5 @@
              ssh $local_user@gaiad "cd $local_wdir; scp -p $2 $remote_user@$1:${catalog_name}batch_scp_append_file.$random"  > /dev/null
           else
-             scp -p $2 $remote_user@$1:${catalog_name}batch_scp_append_file.$random  > /dev/null
+             scp -P 22 -p $2 $remote_user@$1:${catalog_name}batch_scp_append_file.$random  > /dev/null
           fi
           if [[ $? != 0 ]]
@@ -617,5 +620,5 @@
                 remote_size=`ssh $local_user@gaiad "ssh $1 -l $remote_user \"ls -al ${catalog_name}batch_scp_append_file.$random\" "`
              else
-                remote_size=`ssh $1 -l $remote_user "ls -al ${catalog_name}batch_scp_append_file.$random"`
+                remote_size=`ssh $1 -p 22 -l $remote_user "ls -al ${catalog_name}batch_scp_append_file.$random"`
              fi
              remote_size=`echo $remote_size | cut -d" " -f5`
@@ -636,5 +639,5 @@
              ssh $local_user@gaiad "ssh $1 -l $remote_user \"cd $3; cat batch_scp_append_file.$random >> $4$zyklusnr; rm batch_scp_append_file.$random; echo '*** append complete'\" " > $filelist
           else
-             ssh $1 -l $remote_user "cd $3; cat batch_scp_append_file.$random >> $4$zyklusnr; rm batch_scp_append_file.$random; echo '*** append complete'" > $filelist
+             ssh $1 -p 22 -l $remote_user "cd $3; cat batch_scp_append_file.$random >> $4$zyklusnr; rm batch_scp_append_file.$random; echo '*** append complete'" > $filelist
           fi
           if [[ $? != 0 ]]
@@ -656,5 +659,5 @@
           ssh $local_user@gaiad "ssh $1 -l $remote_user \"mkdir -p $3\" "
        else
-          ssh $1 -l $remote_user "mkdir -p $3"
+          ssh $1 -p 22 -l $remote_user "mkdir -p $3"
        fi
        if [[ $? != 0 ]]
@@ -666,5 +669,5 @@
           ssh $local_user@gaiad "cd $local_wdir; scp -p $2 $remote_user@$1:$catalog_name$4$zyklusnr"  > /dev/null
        else
-          scp -p $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
+          scp -P 22 -p $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
        fi
        if [[ $? != 0 ]]
@@ -690,5 +693,5 @@
              ssh $local_user@gaiad "cd $local_wdir; scp -p $remote_user@$1:$catalog_name$4$zyklusnr $2"  > /dev/null
           else
-             scp -p $remote_user@$1:$catalog_name$4$zyklusnr $2  > /dev/null
+             scp -P 22 -p $remote_user@$1:$catalog_name$4$zyklusnr $2  > /dev/null
           fi
           if [[ $? != 0 ]]
