Solved

script question

Posted on 2002-06-30
10
279 Views
Last Modified: 2010-04-21
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 .
0
Comment
Question by:csdnchen
10 Comments
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
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.
0
 
LVL 6

Expert Comment

by:bira
Comment Utility
echo "Enter the password"
stty -echo
read password
stty sane
echo "The Password is : $password"
0
 

Author Comment

by:csdnchen
Comment Utility
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
0
 
LVL 1

Expert Comment

by:NTIVER
Comment Utility
listening...
0
 
LVL 9

Expert Comment

by:PeterMac
Comment Utility
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.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Expert Comment

by:dkloes
Comment Utility
Not sure what version of Unix you are running.  In Red Hat Linux, the following passwd command works:

echo "password"|passwd root --stdin
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
which passwd will do that, /usr/bin/passwd?
0
 
LVL 1

Expert Comment

by:dkloes
Comment Utility
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.
0
 
LVL 20

Expert Comment

by:tfewster
Comment Utility
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
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now