【发布时间】:2020-11-02 04:23:34
【问题描述】:
我想编写一个 bash 脚本来自动化特定过程。
它通过传递标识符启动分析 cms 工具。
传递标识符后,该工具要求输入用户密码。
该脚本应通读此类标识符的列表,并在每个转发的标识符之后输入用户密码。
以下简单示例显示了带有名为“eventDatePicker”的标识符的流程:
jmm@workstation:/opt/media/tools/bin$ ./cm old-viewtypes-usage -u admin -s "/test/" -t "/home/media/transfer" -vt eventDatePicker
password:
到目前为止,这是我创建的 bash 脚本,但我不知道如何实现传递用户密码的函数:
#!/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"
我使用read 或expect 进行了尝试,但没有成功。
我很乐意为您提供任何帮助。
【问题讨论】:
-
答案取决于
./cm命令的内部结构。例如,如果它从标准输入读取密码,则以下内容将起作用:./cm your_args <<<"$password"其中 shell 变量password包含密码。 (当然,对于your_args,请替换您的参数列表。) -
查看
expect。 -
你可以用这个cm来读取密码:
while IFS= read -r line do ./cm your_args <<EOF # command for passing the user password EOF done < "$input"
标签: linux bash shell passwords parameter-passing