Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to supply an input value to the prompt via shell script?

Tags:

linux

bash

shell

I am writing a wrapper shell script wrapper.sh to run bunch of other already available scripts owned by other people and I cannot touch those scripts.

The problem is, there is one script that runs some db specific activities - db_perf_clean.sh. That script is normally executed manually and it prompts for a password at run time. There is no way I can supply the password to it as a parameter and I cannot modify that script. As such I know the db password and I can provide it in wrapper.sh.

Please let me know how can I run that db_perf_clean.sh script inside wrapper.sh like in a silent mode.

like image 604
dganesh2002 Avatar asked Nov 05 '25 19:11

dganesh2002


1 Answers

Sometimes a script will insist that a password be read from the tty. Often, it will read from stdin. If so, try:

echo password | db_perf_clean.sh

The above has the disadvantage that the password will appear in ps. To avoid that, hide the password in a file and use that file for stdin:

db_perf_clean.sh <file_with_password

If you want the command to be silent, you can throwaway its output:

db_perf_clean.sh <file_with_password >/dev/null 2>&1

Under bash, as opposed to generic shell, that can be slightly simplified:

db_perf_clean.sh <file_with_password &>/dev/null
like image 170
John1024 Avatar answered Nov 07 '25 10:11

John1024



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!