Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2018
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.86 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. FOLDER_PATH=$1
  4. ARCHIVE_NAME=$2
  5. DEST_ADDRESS=$3
  6. DEST_DIR=$4
  7. SRC_PASSWORD=$5
  8. DEST_USER=$6
  9. DEST_PASSWORD=$7
  10.  
  11. sshpass -p $SRC_PASSWORD
  12.  
  13. # Checks if the directory exist
  14. if [ ! -d $1 ];
  15. then
  16.     echo $FOLDER_PATH
  17.     echo 'ERROR - such directory does not exist!'
  18.     exit 1
  19. fi
  20.  
  21. # Checks if the SSHPASS is installed
  22. if [ ! $(which sshpass) ];
  23. then
  24.     apt install sshpass
  25. fi
  26.  
  27. # Give permisions
  28. chmod -R 777 $PWD/
  29. chmod -R 777 $FOLDER_PATH/
  30.  
  31. # Copying files to temporary directory
  32. cp -r $FOLDER_PATH/. $PWD/temp
  33. chmod -R 777 temp/
  34. cd temp
  35.  
  36. # Creating temporary archive of copied files
  37. FILES=$(dir)
  38. tar -cf "$ARCHIVE_NAME.tar.gz" $FILES
  39.  
  40. # Copy archive file to server via ssh
  41. sshpass -p $DEST_PASSWORD scp -r "$ARCHIVE_NAME.tar.gz" "$DEST_USER@$DEST_ADDRESS:$DEST_DIR"
  42.  
  43. # Getting archive and deleting temporary files and folder
  44. cd ..
  45. rm -rf temp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement