Hello Everyone,
I do Django web development on my Mac at home, and then I rsync the files with the Ubuntu web server. I want to write one single bash shell script that rsyncs the files and restarts Apache on the server.
Here is the script I have so far, sync.sh:
#!/bin/bash
echo -n Password:
read -s PW
rsync --compress --times --perms --links --recursive --delete --include-from=incls.txt --exclude "*" /User/bollweevil/django-site/* awesomewebsite49.com:websites/scripts
echo $PW | ssh awesomewebsite49.com sudo /etc/init.d/apache2 reload
This script works, but it is kind of annoying because it prompts me for the SSH password twice. It prompts me for the SUDO password only once (lines 2 and 3 prompt, line 5 uses it), but it prompts me for the SSH password twice. I tried this:
echo -n SSH Password:
read -s SSH_PW
echo $SSH_PW | rsync ...
But it didn't work, it just prompted me for the SSH password again. It didn't print the $SSH_PW in cleartext to the screen.
How can I make this work? How can I make it prompt me for the SSH password only once? In this script, it saves me a tiny bit of work. In a more complex script, it could save me a huge amount of work.
Also, is this safe? I am never writing down the password in cleartext, but it is the root password for the web server, and it does exist as cleartext inside that variable. That variable would never do something stupid like reveal its contents during a traceback, would it?
Thanks.