[英]expect + change directory in expect script
We create the following simple expect script in order to run the netdata-installer.sh
我们创建以下简单的
netdata-installer.sh
脚本以运行netdata-installer.sh
expect script is: 期望脚本是:
#!/usr/bin/expect
set timeout 20
send "cd /tmp/netdata\r"
spawn "bash netdata-installer.sh"
expect ">" { send "\r" }
interact
A few words about the netdata-installer.sh
: 关于
netdata-installer.sh
几句话:
In order to run the - netdata-installer.sh
, we need to run it from the working directory - /tmp/netdata
, and this is the reason for me to use in expect the following: 为了运行
netdata-installer.sh
,我们需要从工作目录- /tmp/netdata
运行它,这就是我期望使用以下命令的原因:
send "cd /tmp/netdata\r"
Then in the expect script I use: (in order to execute ENTER
, by this way we start the netdata installation) 然后在Expect脚本中,我使用:(为了执行
ENTER
,通过这种方式我们开始进行netdata安装)
expect ">" { send "\r" }
Until now, it seems things are perfect, but when we run the expect we get: 到目前为止,似乎一切都很完美,但是当我们运行期望时,我们会得到:
# ./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
It seems that the expect script does not change the working directory to cd /tmp/netdata
似乎期望脚本不会将工作目录更改为
cd /tmp/netdata
So where am I wrong? 那我在哪里错了?
example when we do manual installation: 手动安装的示例:
./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
Reference - https://www.ostechnix.com/netdata-real-time-performance-monitoring-tool-linux/ 参考-https: //www.ostechnix.com/netdata-real-time-performance-monitoring-tool-linux/
Remark - the fact that when running the netdata
we need only to give "ENTER" then maybe there are other option to automate this installation ? 备注-事实上,在运行
netdata
我们只需要输入“ ENTER”,然后也许还有其他选项可以自动执行此安装?
与其尝试构建一个可以读取文本并按下虚拟键的软件机器人,不如要求该程序以非交互方式进行安装:
cd /tmp/netdata && ./netdata-installer.sh --dont-wait
we succeeded to automate the process as the following way ( not by expect ) 我们通过以下方式成功实现了流程的自动化(并非意料之外)
cd /tmp/netdata
echo -ne '\n' | bash netdata-installer.sh
You write: 你写:
spawn "bash netdata-installer.sh"
That takes bash netdata-installer.sh
as a single value to run, with the space, and then can't find it. 这
bash netdata-installer.sh
作为带有空格的要运行的单个值,然后找不到它。 Unsurprisingly. 毫不奇怪。 You should pass that as several arguments:
您应该将其作为几个参数传递:
spawn bash netdata-installer.sh
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.