LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE
User Name
Password
SUSE / openSUSE This Forum is for the discussion of Suse Linux.

Notices


Reply
  Search this Thread
Old 03-14-2011, 01:19 PM   #1
s_linux
Member
 
Registered: Jul 2009
Posts: 83

Rep: Reputation: 15
read password with no display


Hello All,
I'm running the following script locally and it works as expected but when I ran over ssh (kick of this script from server1 to run on server2), I'm having issue.
Quote:
#!/bin/bash
echo -n "Please enter your ID : "
read ID
ADMUSER=$ID.domain.com
echo -n "Please enter the password for $ADMUSER: "
read PASSWD
so when I kick of the script from server1, it ask me to enter the ID and that works as expected but when it ask me for the password, I enter it, but it displays on the screen.
How can I make it without displaying the password on the screen.
I tried "read -sp" but did not work
Thanks again
 
Old 03-14-2011, 02:04 PM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
You can use the following:
Code:
stty -echo
read password
stty echo
Cheers,

Josh
 
Old 03-14-2011, 02:11 PM   #3
s_linux
Member
 
Registered: Jul 2009
Posts: 83

Original Poster
Rep: Reputation: 15
Thanks for your reply.
That did not work. Got following..
Please enter your LAN ID): testa
stty: standard input: Invalid argument
Please enter the password for testa.domaim.com: stty: standard input: Invalid argument
drains99
 
Old 03-14-2011, 02:18 PM   #4
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Can you post the full code of your script? I want to run it on my machine so I can debug it for you.
 
Old 03-14-2011, 02:47 PM   #5
s_linux
Member
 
Registered: Jul 2009
Posts: 83

Original Poster
Rep: Reputation: 15
Thats all I have in the script right now and I'm testing with it. If it does that work I wanted to use it in several scripts.
 
Old 03-14-2011, 02:56 PM   #6
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Code:
#!/bin/bash
read -p "Please enter your username: " ID
ADMUSER=$ID.domain.com
stty -echo
read -p "Please enter the password for $ADMUSER: " PASSWD
stty echo
echo "debug: $PASSWD"
This code works on my system. Test it out....
 
1 members found this post helpful.
Old 03-14-2011, 03:10 PM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
The code suggested by corp769 works for me, too! I wrote a similar one some time ago: it disables the echo as well and prints an asterisk at each keystroke. You can take a look here.
 
Old 03-14-2011, 03:11 PM   #8
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Quote:
Originally Posted by colucix View Post
The code suggested by corp769 works for me, too! I wrote a similar one some time ago: it disables the echo as well and prints an asterisk at each keystroke. You can take a look here.
Maybe he's missing something? I know stty is part of the coreutils package, maybe he don't have certain libs?
 
Old 03-14-2011, 03:18 PM   #9
s_linux
Member
 
Registered: Jul 2009
Posts: 83

Original Poster
Rep: Reputation: 15
It still does not work.

+ echo -n 'Please enter a valid remote IP (for replica sync): '
Please enter a valid remote IP: + read remoteip
10.67.132.110
+ for i in '$remoteip'
+ ssh 10.67.132.110 /tmp/edir886/testc.sh
-p Please enter your ID:
i301685
stty: standard input: Invalid argument
-p Please enter the password for testa.domain.com:
drains99
stty: standard input: Invalid argument
debug: drains99

Here is the script thats kicking from server1 to run on server2
Quote:
#!/bin/bash
set -x
echo -n "Please enter a valid remote IP: "
read remoteip
for i in $remoteip
do
ssh ${i} /tmp/edir886/testc.sh
done
Script on server2
Quote:
#!/bin/bash
echo -p "Please enter your ID: "
read ID
ADMUSER=$ID.domain.com
stty -echo
echo -p "Please enter the password for $ADMUSER: "
read PASSWD
stty echo
echo "debug: $PASSWD"
As I said earlier, if I run the script on server2 manually that works.
 
Old 03-14-2011, 03:30 PM   #10
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
stty must be connected to a (pseudo)terminal to work properly. You can try to force the pseudo terminal allocation through ssh with the -t option.

Also note that echo has not a -p option. The suggested code had the -p option in the read statement to prompt the user with a question. In other words the following are equivalent:
Code:
echo "Would you like a cup of tea? "
read answer
and
Code:
read -p "Would you like a cup of tea? " answer
 
Old 03-14-2011, 03:32 PM   #11
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
To the OP - And that's why I said to post the code earlier before. I could have also told you what repo said
 
Old 03-14-2011, 04:14 PM   #12
s_linux
Member
 
Registered: Jul 2009
Posts: 83

Original Poster
Rep: Reputation: 15
looks like -t option with ssh did the trick. Thanks Colucix
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
display of password characteristics, or parameters Cerephim Linux - Server 4 10-22-2009 03:40 PM
If you have display problems PLEASE READ! chrisortiz Linux - Laptop and Netbook 1 08-02-2006 12:27 AM
Read and display the my own IP address in C? eric_pena Programming 3 02-09-2006 09:29 PM
bashrc not read by root, can't open display SerfurJ Slackware 6 12-05-2003 10:54 PM
read other posts but still can't change display pires Linux - Newbie 5 08-25-2003 09:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE

All times are GMT -5. The time now is 03:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration