home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / MINIX9.ZIP / MINIX9.TD0 / bin / rcp < prev    next >
Encoding:
Text File  |  1989-10-03  |  1.4 KB  |  77 lines

  1. : Copy a file from any machine to any other machine.
  2. usage="Usage: $0 [machine!]from-file [machine!]to-file"
  3. PATH=/usr/local:/bin:/usr/bin
  4. CDPATH=
  5. case $# in
  6. 2)    :
  7.     ;;
  8. *)    echo "$usage" 1>&2
  9.     exit 1
  10. esac
  11. from=$1 to=$2
  12. case $from in
  13. *!*)    IFS="!"
  14.     set $from
  15.     case $# in
  16.     2)    from_mach=$1 from_file=$2 IFS=" "
  17.         ;;
  18.     *)    echo "$usage" 1>&2
  19.         exit 1
  20.     esac
  21.     ;;
  22. *)    from_file=$from
  23. esac
  24. case "$from_file" in
  25. "")    echo "$usage" 1>&2
  26.     exit 1
  27. esac
  28. case $to in
  29. *!*)    IFS="!"
  30.     set $to
  31.     case $# in
  32.     2)    to_mach=$1 to_file=$2 IFS=" "
  33.         ;;
  34.     *)    echo "$usage" 1>&2
  35.         exit 1
  36.     esac
  37.     ;;
  38. *)    to_file=$to
  39. esac
  40. case "$to_file" in
  41. "")    echo "$usage" 1>&2
  42.     exit 1
  43. esac
  44. case "$from_mach" in
  45. "$to_mach")
  46.     : machines equal
  47.     case "$to_mach" in
  48.     "")    : local
  49.         cp "$from_file" "$to_file"
  50.         ;;
  51.     *)    : remote
  52.         rsh "$to_mach" "cp $from_file $to_file"
  53.         ;;
  54.     esac
  55.     ;;
  56. *)    : machines not equal
  57.     case "$to_mach" in
  58.     "")    : to local
  59.         if test -d "$to_file"
  60.         then    rsh -e "$from_mach" "cat $from_file" >"$to_file/`basename $from_file`"
  61.         else    rsh -e "$from_mach" "cat $from_file" >"$to_file"
  62.         fi
  63.         ;;
  64.     *)    : to remote
  65.         case "$from_mach" in
  66.         "")    : from local
  67.             rsh -i "$to_mach" "if test -d $to_file; then cat >$to_file/`basename $from_file`; else cat >$to_file; fi" <"$from_file"
  68.             ;;
  69.         *)    : from remote
  70.             rsh -e "$from_mach" "cat $from_file" | rsh -i "$to_mach" "if test -d $to_file; then cat >$to_file/`basename $from_file`; else cat >$to_file; fi"
  71.             ;;
  72.         esac
  73.         ;;
  74.     esac
  75.     ;;
  76. esac
  77.