opscp 3.0 KB

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