Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- FOLDER_PATH=$1
- ARCHIVE_NAME=$2
- DEST_ADDRESS=$3
- DEST_DIR=$4
- SRC_PASSWORD=$5
- DEST_USER=$6
- DEST_PASSWORD=$7
- sshpass -p $SRC_PASSWORD
- # Checks if the directory exist
- if [ ! -d $1 ];
- then
- echo $FOLDER_PATH
- echo 'ERROR - such directory does not exist!'
- exit 1
- fi
- # Checks if the SSHPASS is installed
- if [ ! $(which sshpass) ];
- then
- apt install sshpass
- fi
- # Give permisions
- chmod -R 777 $PWD/
- chmod -R 777 $FOLDER_PATH/
- # Copying files to temporary directory
- cp -r $FOLDER_PATH/. $PWD/temp
- chmod -R 777 temp/
- cd temp
- # Creating temporary archive of copied files
- FILES=$(dir)
- tar -cf "$ARCHIVE_NAME.tar.gz" $FILES
- # Copy archive file to server via ssh
- sshpass -p $DEST_PASSWORD scp -r "$ARCHIVE_NAME.tar.gz" "$DEST_USER@$DEST_ADDRESS:$DEST_DIR"
- # Getting archive and deleting temporary files and folder
- cd ..
- rm -rf temp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement