C shell script rc2lm



# !/bin/csh -f
# =============================================================================
# FILE: rc2lm
# DATE: 11 July 1997
#
# DESC: Usage:  rc2lm [file name 1] [etc...] [local target directory]
#
#       Performs a remote copy of files from middlepark / winterpark to a
#       designated local machine via (in pseudo script):
#
#       /usr/bsd/rcp -p -v [file name 1] \
#                           $loc_mac_ipa:/$loc_hom_dir/[local target directory]
#
#       /usr/bsd/rcp -p -v [etc...] \
#                           $loc_mac_ipa:/$loc_hom_dir/[local target directory]
#
#       where loc_mac_ipa is the local machine IP address and loc_hom_dir is
#       the local home directory. If local target directory given by the last
#       argument does not exist, it is created after prompting for permission. 
#       In this case the local target directory can be only a single name which
#       will be created as a subdirectory below the home directory.
#       
#       Metacharacters for filename expansion such as *.f90 may be used
#       to indicate a suite of filenames. More than one metacharacter file
#       name expansion may be used. File names and file name expansions are
#       entered as separate arguments, followed by the last argument which is
#       the local target directory.
#
#       The shell variables loc_mac_ipa and loc_hom_dir must be set below.
#
# =============================================================================
# Check for 0 arguments:

  if ( $#argv == 0 ) then 
   echo "USAGE: rc2sp [file name 1] [etc...] [local target directory]"
   exit
  endif

# -----------------------------------------------------------------------------
# Assign local machine IP, local home directory, local target directory, and
# `which' path:

  set loc_mac_ipa = 128.117.22.12    # Local machine IP address.

  set loc_hom_dir = /u5/davestep     # Local home directory. 

  set loc_tgt_dir = $argv[$#argv]    # Local target directory.

    set which_rcp = `which rcp`      # Remote copy (rcp). 
 
    set which_rsh = `which rsh`      # Remote shell (rsh).

      set fil_out = rsh_ls_query.out # Temporary diagnostic file
 
# -----------------------------------------------------------------------------
# Check if local target directory exists. If not ask permission to create it:
 
  $which_rsh $loc_mac_ipa ls -d $loc_hom_dir/$loc_tgt_dir > $fil_out
 
  if ( -z $fil_out ) then
 
       echo "                                                          "
       echo "  Do you  want to create local target  directory (y or n)?"
       echo "  [If you are creating a local target directory it must be"
       echo "  a single name (not a path) which will be  added as a new"
       echo "  subdirectory below the local home directory.]           "
       echo "                                                          "
    echo -n "                                           RESPOND HERE: "
 
      set a = $<
 
   if ( $a == y ) then
 
       echo "                                                          "
    echo -n "                     Enter the new local target directory."
       echo "                                                          "
    echo -n "                                           RESPOND HERE: "
 
   set nltd = $<
 
   set loc_tgt_dir = $nltd
 
   $which_rsh $loc_mac_ipa mkdir $loc_hom_dir/$loc_tgt_dir
 
   else
 
       echo "                                                          "
       echo "  You have chosen not to create a  new local target direc-"
       echo "  tory. Bye!                                              "
       echo "                                                          "
       /bin/rm $fil_out
       exit
 
   endif
 
 
  endif
 
  /bin/rm $fil_out

# -----------------------------------------------------------------------------
# Do remote copy of files to host target directory: (Note: Double quotes en-
# close the colon to keep what follows from being interpreted as a pathname
# specifier (or modifier) for a pathname variable.)

  @ num_fn_arg = $#argv - 1     # Number of file name arguments.

  foreach file ($argv[1-$num_fn_arg])

   $which_rcp -p -v $file $loc_mac_ipa":"$loc_hom_dir/$loc_tgt_dir

  end 

# =============================================================================
# End of C shell script rc2lm.
# =============================================================================