Operating System - HP-UX
1751830 Members
5136 Online
108782 Solutions
New Discussion юеВ

Re: Blank an entered value...

 
SOLVED
Go to solution
Jonathan Caplette_1
Super Advisor

Blank an entered value...

Hi guys,

I want to script the transfer of files with FTP, but I don't want to assign my password to a value, like user_passwd="password",

I was thinking instead of reading the password like this, read user_passwd, but I would like that when I'm at the prompt the keys that I enter to be not showed at the screen, just like when you issue the passwd commant!! See what I mean!?

Is this possible???

Thanks
Jonathan
6 REPLIES 6
Stephen Keane
Honored Contributor
Solution

Re: Blank an entered value...

If you mean a shell scripts, you could use something like

stty -echo

... get password ...

stty echo

A. Clay Stephenson
Acclaimed Contributor

Re: Blank an entered value...

The key to what you want is "stty -echo" BUT make sure that you have a trap statement to do a "stty echo" so that if the script terminates or receives a SIGHUP, SIGINT, etc. that the terminal is restored to stty echo. The stty command applies not to the process but rather to the terminal itself so that if you exit the script with echo off, it's still off.

The idea is:

echo "Enter Login: \c"
read LOGIN
echo "\nEnter Password: \c"
stty -echo
read PASSWD
stty echo

By the way, you can also create a .netrc file so that you don't have to prompt for the passwd. The file should only be able to be read by that user.

If it ain't broke, I can fix that.
RAC_1
Honored Contributor

Re: Blank an entered value...

While you can use stty echo for this, be aware that, you should use trap command in the script. Else, a termination of script will leave terminal in "stty echo" mode.

trap 'stty echo; exit' 0 1 2 3 15
echo "Enter Password: \c"
stty -echo
read PASSWD
stty echo


Also you may want to have a look at expect tool for this. You can also make use of .netrc file.

Or a better way is to use ssh for this.
There is no substitute to HARDWORK
Jonathan Caplette_1
Super Advisor

Re: Blank an entered value...

thanks guys,

this work fine!!

stty -echo
read user_passwd
stty echo

Now I got another question... Can I log every thing that is done when the ftp is done?

RAC_1
Honored Contributor

Re: Blank an entered value...

man ftp. check -v and i options.
There is no substitute to HARDWORK
Jonathan Caplette_1
Super Advisor

Re: Blank an entered value...

thanks

-v options work!!