473,396 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Making a bash script only prompt for password once?

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.
Apr 6 '09 #1
3 12032
Hello Everyone,

I wish I could edit my earlier post, but I can't. The earlier post asks how to make a bash script fill in the password when prompted. I found something that does exactly that: expect.

Expect successfully fills in the password, BUT it breaks something else. Here is the new and improved code, in sync.sh:
Expand|Select|Wrap|Line Numbers
  1. #!/bin/bash
  2. echo -n Password:
  3. read -s PW
  4. expect -c 'spawn rsync --verbose --stats --progress --compress --times --perms --links --recursive --delete --include-from=incls.txt --exclude "*" /Users/bollweevil/django-site/* awesomewebsite49.com:websites/scripts' -c 'expect password:' -c 'send '$PW'\n' -c 'expect eof'
  5.  
So, let's invoke ./sync.sh
It almost works. "rsync" gets called, it prompts for a password, then "expect" feeds it a password, and the remote server likes the password and accepts it. rsync starts to display its status. And then...
Expand|Select|Wrap|Line Numbers
  1. building file list ... 
  2. rsync: link_stat "/Users/bollweevil/django-site/*" failed: No such file or directory (2)
  3. 0 files to consider
  4.  
What? What's wrong? Let's copy the "rsync ..." line out of the "spawn ..." statement, just a completely direct copy, and then paste it right into the shell:
Expand|Select|Wrap|Line Numbers
  1. new-host: bollweevil$ rsync --verbose --stats --progress --compress --times --perms --links --recursive --delete --include-from=incls.txt --exclude "*" /Users/bollweevil/django-site/* awesomewebsite49.com:websites/scripts
  2. building file list ... 
  3. 45 files to consider
  4.  
What?! Why does it work perfectly now? I copied it exactly! Clearly, "expect" or "spawn" is doing crazy crap and messing things up.

Please help.

Thanks.
Apr 6 '09 #2
gpraghuram
1,275 Expert 1GB
Try to use expect so it wont ask the password again.

Thanks
raghu
Apr 7 '09 #3
ashitpro
542 Expert 512MB
You can automate ssh as well rsync...
All you need to do is exchange secure key at both machines..
Follow the link:
http://www.astro.umd.edu/~teuben/sirtf/ssh.html
Apr 7 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: |-|erc | last post by:
Hi! Small challenge for you. The index.php uses this file and calls layout(). Take a look at www.chatty.net this file draws the chat login box on the right. I traced the CHAT button it submits...
2
by: Eric Woudenberg | last post by:
I just installed a Python 2.3.4 Windows binary on a friend's WinXP machine (because the latest Cygwin-provided Python 2.3 build leaves out the winsound module for some reason). When I try and...
2
by: Dmitry | last post by:
Hi folks! I need to find a way to switch to a different Unix user from within the Perl script that is currently ran unattended. Script must switch user in order to execute proper profile for...
5
by: F. Biguet | last post by:
Hello, I want to create a generic script that connects to Oracle databases (from 7.3.4 to 9.2 version) with a guest user. This script should return 1 if connection is successful and 0 if not....
10
by: Max | last post by:
Hello all, I am trying to protect a page within my site with a JS password scheme. Now I know JS can be quite easily "circumvented", but I came by a code below. My question is: 1. Is there...
8
by: Jan Danielsson | last post by:
Hello all, How do I make a python script actually a _python_ in unix:ish environments? I know about adding: #!/bin/sh ..as the first row in a shell script, but when I installed python on...
1
by: jodyblau | last post by:
I applogize for posting this a second time (I posted in the access-multiuser group as well), but this group seems to respond more rapidly, and I have been trying to figure this out for what seems...
16
by: John Salerno | last post by:
Hi all. I just installed Ubuntu and I'm learning how to use the bash shell. Aside from the normal commands you can use, I was wondering if it's possible to use Python from the terminal instead of...
0
by: lokeshrajoria | last post by:
Hello Everyone, Please go through this script code . this script files executing in bash 2.05 version without mentioning sh. That means if I type simple in command prompt :...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.