*not* just another blog ;)

Automating rsync with sshpass

- Posted in Quick Tip by with comments

I have made a script that every 5 minutes downloads a still shot of the weather radar in my area and saves it into a folder on my server. This is done using a bash script and crontab.

On my computer, I've made a bash script to sync them, but it requires me to enter my password all the time for rsync.

I found a solution to that called sshpass.

First, we need to install it:

apt install sshpass

Now, we can use it. In my case, I'm using a bash script and a cron job to sync them every hour. Here's what my bash script looks like, using sshpass:

echo "Setting up.."
export SSHPASS=supersecretpassword
echo "Syncing..."
sshpass -e rsync -Aax --progress [email protected]:/remotefolder /localfolder
echo "Cleaning up.."
echo "Done!"

The main thing is that you set the password variable, and keep the -e tag in sshpass (tells it to use an environment variable)

Hopefully that helps someone!

Using Rsync

- Posted in Quick Tip by with comments

I found myself needing a copy a folder from one server to another, but keeping all of the file attributes intact and not copying files already transferred, or deleting anything.

I came across this command:

rsync --progress -havz /var/www [email protected]:/var/www

Which shows the progress as it goes, keeps the file attributes and doesn't copy anything that's already there.