pushToRemote_batch.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. # check input
  3. if [ -z "$1" ]; then
  4. echo "*************************************************************************************"
  5. echo
  6. echo " Usage: ./pushToRemote_batch.sh /PATH/TO/FILE"
  7. echo
  8. echo "*************************************************************************************"
  9. echo
  10. exit 1
  11. fi
  12. FBS_ESC=`echo -en "\033"`
  13. COLOR_RED="${FBS_ESC}[1;31m"
  14. COLOR_GREEN="${FBS_ESC}[1;32m"
  15. COLOR_CLOSE="${FBS_ESC}[0m"
  16. cd $(dirname $0)
  17. # check scirpt exists
  18. [ -x ./pushToRemote.sh ] || { echo "need pushToRemote.sh with \"x\" privilege, exit"; exit 1; }
  19. # check file exists
  20. [ -f "$1" ] || { echo "$1 dose't exists"; exit 1; }
  21. # check the file content
  22. # file content should start with "registry.svicloud.com/*" only
  23. FILTERED_ROWS=`sed -n '/^$/!p' $1 | sed -n '/^ *#/!p'`
  24. if echo "$FILTERED_ROWS" | grep -vq "^ *registry.svicloud.com/"; then
  25. echo "content in $i error, only \"registry.svicloud.com/*\" support"
  26. exit 1
  27. fi
  28. BASEFILE=`basename $0`
  29. LOG_FILE=/var/log/${BASEFILE%.*}.log
  30. echo "" >>$LOG_FILE; echo "[`date "+%Y-%m-%d %H:%M:%S"`]" >>$LOG_FILE
  31. # loop
  32. LOOP_ROWS=`sed -n '/^$/!p' $1 | sed -n '/^ *#/!p' | \
  33. grep "^ *registry.svicloud.com/" | sort | uniq`
  34. for i in $LOOP_ROWS; do
  35. echo; echo "################ $i"
  36. ./pushToRemote.sh $i && \
  37. { echo "################ ${COLOR_GREEN}success${COLOR_CLOSE}"; echo ; echo -e "success\t$i" >>$LOG_FILE; } || \
  38. { echo "################ ${COLOR_RED}error${COLOR_CLOSE}"; echo ; echo -e "error\t$i" >>$LOG_FILE; }
  39. done