2

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.

3
  • The answer depends on the internals of the ./cm command. If it reads the password from stdin, as an example, then the following would work: ./cm your_args <<<"$password" where the shell variable password contains the password. (For your_args, of course, substitute your argument list.) Commented Jul 13, 2020 at 1:39
  • Look into expect. Commented Jul 13, 2020 at 2:49
  • You can use this for cm to read the password : while IFS= read -r line do ./cm your_args <<EOF # command for passing the user password EOF done < "$input" Commented Jul 13, 2020 at 3:59

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.