Re: Blank an entered value... (164 Views)
Reply
Super Advisor
Jonathan Caplette_1
Posts: 299
Registered: ‎09-18-2002
Message 1 of 7 (164 Views)
Accepted Solution

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
Please use plain text.
Honored Contributor
Stephen Keane
Posts: 1,155
Registered: ‎11-24-2004
Message 2 of 7 (164 Views)

Re: Blank an entered value...

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

stty -echo

... get password ...

stty echo

Please use plain text.
Acclaimed Contributor
A. Clay Stephenson
Posts: 17,825
Registered: ‎07-16-1998
Message 3 of 7 (164 Views)

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.
Please use plain text.
Honored Contributor
RAC_1
Posts: 5,920
Registered: ‎03-21-2002
Message 4 of 7 (164 Views)

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
Please use plain text.
Super Advisor
Jonathan Caplette_1
Posts: 299
Registered: ‎09-18-2002
Message 5 of 7 (164 Views)

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?

Please use plain text.
Honored Contributor
RAC_1
Posts: 5,920
Registered: ‎03-21-2002
Message 6 of 7 (164 Views)

Re: Blank an entered value...

man ftp. check -v and i options.
There is no substitute to HARDWORK
Please use plain text.
Super Advisor
Jonathan Caplette_1
Posts: 299
Registered: ‎09-18-2002
Message 7 of 7 (164 Views)

Re: Blank an entered value...

thanks

-v options work!!
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation