Link to home
Start Free TrialLog in
Avatar of csdnchen
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 .
Avatar of ahoffmann
ahoffmann
Flag of Germany image

for common purpose you simply can use a file to read the answers from, like:
  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.
Avatar of bira
bira

echo "Enter the password"
stty -echo
read password
stty sane
echo "The Password is : $password"
Avatar of csdnchen

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
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
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.
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
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial