简体   繁体   中英

How can I pass a password to bash script

I'd like to write a bash script which automates a specific process. It starts an analyzing cms-tool with passing an identifier. After passing an identifier that tool is asking for user password. The script should read through a list of such identifiers and input the user password after each forwarded identifier.
The following simple example shows the process with an identifier called 'eventDatePicker':

jmm@workstation:/opt/media/tools/bin$ ./cm old-viewtypes-usage -u admin -s "/test/" -t "/home/media/transfer" -vt eventDatePicker

password:

This is my created bash script so far but I don't know how to implement a function for passing a user password:

#!/bin/bash
# list with identifiers
input="/opt/media/tools/bin/technical_identifier"
#path to analyzing tool
cd /opt/media/tools/bin || exit
while IFS= read -r line
do
       ./cm old-viewtypes-usage -u admin -s "/test/" -t "/home/media/transfer" -vt "$line"
        # command for passing the user password 
       
done < "$input"

I tried it out by using read or expect but it didn't work out. I'd be glad for any help.

You might like to learn the 'expect' dialect of Tcl. Start with running 'autoexpect' and then change the output script to take parameters and send your password.

This is really the only sane way of scripting up interactive scripts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM