opscp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/bin/bash
  2. function usage() {
  3. cat << EOF
  4. Usage: opscp [OPTIONS] local remote
  5. Options:
  6. --version show program's version number and exit
  7. --help show this help message and exit
  8. -l USER, --user=USER username (OPTIONAL)
  9. -p PAR, --par=PAR max number of parallel threads (OPTIONAL)
  10. --errdir=ERRDIR output directory for stderr files (OPTIONAL)
  11. --outdir=OUTDIR output directory for stdout files (OPTIONAL)
  12. -e ENV, --env ENV Which environment to use
  13. -t HOST_TYPE, --host-type HOST_TYPE
  14. Which host type to use
  15. -O OPTION, --option=OPTION
  16. SSH option (OPTIONAL)
  17. -v, --verbose turn on warning and diagnostic messages (OPTIONAL)
  18. -A, --askpass Ask for a password (OPTIONAL)
  19. -x ARGS, --extra-args=ARGS
  20. Extra command-line arguments, with processing for
  21. spaces, quotes, and backslashes
  22. -X ARG, --extra-arg=ARG
  23. Extra command-line argument
  24. -r, --recursive recusively copy directories (OPTIONAL)
  25. Example: opscp -t ex-srv -e stg -l irb2 foo.txt /home/irb2/foo.txt
  26. EOF
  27. }
  28. if [ $# -eq 0 ] || [ "$1" == "--help" ]
  29. then
  30. usage
  31. exit 1
  32. fi
  33. PSCP_PAR=200
  34. USER=root
  35. PSCP_OPTIONS=""
  36. ENV=""
  37. HOST_TYPE=""
  38. while [ $# -gt 0 ] ; do
  39. if [ "$1" == "-t" -o "$1" == "--host-type" ] ; then
  40. shift # get past the option
  41. HOST_TYPE=$1
  42. shift # get past the value of the option
  43. elif [ "$1" == "-e" ] ; then
  44. shift # get past the option
  45. ENV=$1
  46. shift # get past the value of the option
  47. elif [ "$1" == "-p" -o "$1" == "--par" ] ; then
  48. shift # get past the option
  49. PSCP_PAR=$1
  50. shift # get past the value of the option
  51. elif [ "$1" == "-l" -o "$1" == "--user" ] ; then
  52. shift # get past the option
  53. USER=$1
  54. shift # get past the value of the option
  55. elif [ "$1" == "-h" -o "$1" == "--hosts" -o "$1" == "-H" -o "$1" == "--host" ] ||
  56. [ "$1" == "-o" ] ; then
  57. echo "ERROR: unknown option $1"
  58. exit 20
  59. else
  60. if [ "${1:0:1}" == "-" ] ; then
  61. # It's an option, don't quote
  62. PSCP_OPTIONS="$PSCP_OPTIONS $1"
  63. else
  64. PSCP_OPTIONS="$PSCP_OPTIONS '$1'"
  65. fi
  66. shift # Get past this option
  67. fi
  68. done
  69. if [ -z "$ENV" ]
  70. then
  71. echo
  72. echo "-e is a required paramemeter"
  73. echo
  74. exit 10
  75. fi
  76. if [ -z "$HOST_TYPE" ]
  77. then
  78. echo
  79. echo "-t is a required paramemeter"
  80. echo
  81. exit 15
  82. fi
  83. PSCP_OPTIONS="-t 0 -p $PSCP_PAR -l $USER -h <(ohi -t $HOST_TYPE -e $ENV 2>/dev/null) $PSCP_OPTIONS"
  84. # See if the ohi options are valid
  85. ohi -t $HOST_TYPE -e $ENV &> /dev/null
  86. ECODE=$?
  87. if [ $ECODE -ne 0 ] ; then
  88. echo
  89. echo "ERROR: ohi failed with exit code $ECODE"
  90. echo
  91. echo "This is usually caused by a bad value passed for host-type or environment."
  92. echo
  93. exit 25
  94. fi
  95. echo
  96. echo "Running: pscp.pssh $PSCP_OPTIONS"
  97. echo
  98. eval pscp.pssh $PSCP_OPTIONS