为了运行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运行它,这就是为什么我要在expect中使用以下命令:
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

expect脚本似乎没有将工作目录更改为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

10-08 00:08