gpt4 book ai didi

linux - 期望+在期望脚本中更改目录

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:32:31 29 4
gpt4 key购买 nike

我们创建以下简单的 expect 脚本以运行 netdata-installer.sh

预期脚本是:

#!/usr/bin/expect

set timeout 20
send "cd /tmp/netdata\r"
spawn "bash netdata-installer.sh"

expect ">" { send "\r" }
interact

关于 netdata-installer.sh 的几句话:

为了运行 - netdata-installer.sh ,我们需要从工作目录 - /tmp/netdata 运行它,这就是我希望使用以下内容:

send "cd /tmp/netdata\r"

然后在我使用的expect脚本中:(为了执行ENTER,这样我们就开始了netdata的安装)

expect ">" { send "\r" }

到目前为止,一切似乎都很完美,但是当我们运行 expect 时,我们得到:

# ./exp.sh
spawn bash netdata-installer.sh
couldn't execute "bash netdata-installer.sh": no such file or directory
while executing
"spawn "bash netdata-installer.sh""
(file "./exp.sh" line 5)
You have new mail in /var/spool/mail/root

似乎期望脚本没有将工作目录更改为cd/tmp/netdata

那我哪里错了?


我们进行手动安装时的示例:

./netdata-installer.sh

^
|.-. .-. .-. .-. . netdata
| '-' '-' '-' '-' real-time performance monitoring, done right!
+----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->


You are about to build and install netdata to your system.

It will be installed at these locations:

- the daemon at /usr/sbin/netdata
- config files in /etc/netdata
- web files in /usr/share/netdata
- plugins in /usr/libexec/netdata
- cache files in /var/cache/netdata
- db files in /var/lib/netdata
- log files in /var/log/netdata
- pid file at /var/run/netdata.pid
- logrotate file at /etc/logrotate.d/netdata

This installer allows you to change the installation path.
Press Control-C and run the same command with --help for help.

Press ENTER to build and install netdata to your system > <--- in this point we need to ENTER

引用 - https://www.ostechnix.com/netdata-real-time-performance-monitoring-tool-linux/

备注 - 在运行 netdata 时,我们只需输入“ENTER”,然后也许还有其他选项可以自动安装?

最佳答案

与其尝试构建一个可以读取文本和按下虚拟键的软件机器人,不如让程序以非交互方式安装:

cd /tmp/netdata && ./netdata-installer.sh --dont-wait

关于linux - 期望+在期望脚本中更改目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57578411/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com