rsync_local.sh 872 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env bash
  2. SCRIPT="$0"
  3. # SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path.
  4. while [ -h "$SCRIPT" ] ; do
  5. ls=`ls -ld "$SCRIPT"`
  6. # Drop everything prior to ->
  7. link=`expr "$ls" : '.*-> \(.*\)$'`
  8. if expr "$link" : '/.*' > /dev/null; then
  9. SCRIPT="$link"
  10. else
  11. SCRIPT=`dirname "$SCRIPT"`/"$link"
  12. fi
  13. done
  14. APP_HOME=`dirname "$SCRIPT"`
  15. export APP_HOME=`cd "$APP_HOME"; pwd`
  16. NODE_USER=$1
  17. TO_PATH=$2
  18. if [ $NODE_USER = ""]; then
  19. echo "Use: rsync_local.sh user@host /path/dir"
  20. exit 2
  21. fi
  22. if [ $TO_PATH = ""]; then
  23. echo "Use: rsync_local.sh user@host /path/dir"
  24. exit 2
  25. fi
  26. echo "APP_HOME=$APP_HOME"
  27. echo "NODE_USER=$NODE_USER"
  28. echo "TO_PATH=$TO_PATH"
  29. echo "sync node: $NODE_USER"
  30. echo rsync -vazu --progress $APP_HOME/* $NODE_USER:$TO_PATH
  31. rsync -vazu --progress $APP_HOME/* "$NODE_USER":$TO_PATH