csdnchen
asked on
script question
how can I write a command line answer in a script , for example if I want to make a script to input a password for a user,
just like this "passwd pgsql" , but I want to write the password in the script .
just like this "passwd pgsql" , but I want to write the password in the script .
echo "Enter the password"
stty -echo
read password
stty sane
echo "The Password is : $password"
stty -echo
read password
stty sane
echo "The Password is : $password"
ASKER
I want to auto input the password by script , I means to write a script to make a user password , the password is written in the script , not input at runtime, it seems not run:
echo "password" |echo "password"|passwd username
echo "password" |echo "password"|passwd username
listening...
ahoffman is right, most programs requesting passwords will go direct to current tty device, not use stdin for password entry, you need something to emulate keyboard entry of password, ie put password directly into keyboard buffer. Even this will not work with all of them, I have known programs deliberately flush keyboard buffer between requesting "username", and "password", to ensure password is manually entered.
Not sure what version of Unix you are running. In Red Hat Linux, the following passwd command works:
echo "password"|passwd root --stdin
echo "password"|passwd root --stdin
which passwd will do that, /usr/bin/passwd?
Yes. RH Linux 7.1.
Sorry it took so long to get back. Did not realize that it had been awhile since I posted and my old e-mail address was being used so did not receive notification.
Sorry it took so long to get back. Did not realize that it had been awhile since I posted and my old e-mail address was being used so did not receive notification.
No comment has been added lately, so it's time to clean up this Topic Area.
I will leave a recommendation for this question in the Cleanup topic area as follows:
- PAQ, no points refunded
Please leave any comments here within the next 7 days
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !
tfewster
Cleanup Volunteer
I will leave a recommendation for this question in the Cleanup topic area as follows:
- PAQ, no points refunded
Please leave any comments here within the next 7 days
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !
tfewster
Cleanup Volunteer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
your-script < file-containing-answers
or:
echo answer | your-script
If it is for programs requesting paswords (like telnet), you need a special script language like expect to do it.