Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm having trouble in making script with interactive login. I have made one but it doesn't ask the login, it automatically log in when i run the script.

i just need the output like this:

please enter ftp server :
username :
password :
share|improve this question
add comment

1 Answer 1

Use read (see help read) - can be like this:

read -p "please enter ftp server : " SERVER
read -p "username : " USERNAM
IFS= read -s -p "password :" USERPSS

In this way, you'll have the server, username and password collected in variables, respectively, $SERVER, $USERNAM and $USERPSS. (Note that because of -s, the password will not be echoed and thanks to IFS=, it can contain space at the beginning.)

Keep in mind that, even though the password is not displayed when prompted, you should not use the $USERPSS variable directly in a command like ftp "${USERNAM}:${USERPSS}@{SERVER}", because it will be revealed to any other user that runs ps (for example) on this computer. Better pass on the password directly as input to the program or (best) just let the program ask for it.

share|improve this answer
    
look into expect for examples of how to do what @rozcietrzewiacz suggested in the last paragraph. –  Tim Kennedy Sep 29 '11 at 11:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.