473,794 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Making a bash script only prompt for password once?

2 New Member
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/* awesomewebsite4 9.com:websites/scripts
echo $PW | ssh awesomewebsite4 9.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 12069
bollweevil
2 New Member
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 Recognized Expert Top Contributor
Try to use expect so it wont ask the password again.

Thanks
raghu
Apr 7 '09 #3
ashitpro
542 Recognized Expert Contributor
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
2768
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 and goes to the index file again, I can't figure out how it opens the chatroom. I want to get it to skip the login box and go straight to the room, with user name "guest" or "" or whatever but I'll add a field to type the name in the chat room....
2
2986
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 run this newly installed Python from bash it just hangs (no version message, no prompt, CPU is idle). When I run it from IDLE, or the DOS CMD prompt, it runs fine. Also, Python scripts using the new version run fine, even invoked on the bash command...
2
8994
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 different Data Base Instance and set corresponding environmental variables correctly. Script works fine for a single Data Base Instance. I need to be able to run it consecutively for several others instances. This requires login in as a different...
5
10391
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. My problem is due to the 3 requests for password when the connection fails. I can't find any option that allows to ask for password only one time. Has anyone already written a such script?
10
6014
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 a way to find a password for this script? How easily? 2. Is there a stronger scheme available in JS?
8
2031
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 a NetBSD system, I didn't get a "python" executable; only a "python2.4"
1
4708
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 like forever. I have the Access 2002 Developer's Handbook, and I am trying to learn from the example provided in Chapter 2, but I am running into the following problem. I set an admin password and a username and password on the backend,
16
3950
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 the normal bash commands (e.g. print instead of echo). My main reason for asking is that I like using Python for everything, and if I don't need to learn the bash 'language', then I won't just yet. Thanks.
0
1507
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 : $moverds.sh then it is execution without any problem and when I try to execute by type in command prompt like: $sh moverds.sh then its giving the following Error root@aramco2.temp.com # sh moverds.sh
0
10433
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10212
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9035
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6777
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4112
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.