[英]Bash calls two bash scripts
I have the following script: 我有以下脚本:
#!/bin/bash
if [ "$EUID" -ne 0 ]
then
echo ''
echo 'Please run the script as root'
echo ''
exit
fi
for run in {1..11}
do
sudo ./start_ap.sh
sleep 10
sudo ./tst.sh
done
The problem is that after executing 问题是执行后
sudo ./start_ap.sh
the next lines will not be executed, because the line sudo ./start_ap.sh needs CTRL+C to stop and only then next lines will be executed. 下一行将不会执行,因为sudo ./start_ap.sh行需要CTRL + C才能停止,然后才执行下一行。
However, I want that the sudo ./start_ap.sh will be terminated after sudo ./tst.sh and at next step this will be repeated 11 times. 但是,我希望sudo ./start_ap.sh在sudo ./tst.sh之后终止,并在下一步将重复11次。
So far, after execution of sudo ./start_ap.sh, the next lines will not be executed without killing its process. 到目前为止,在执行sudo ./start_ap.sh之后,在不终止其进程的情况下将不执行下一行。
How can I realize it? 我怎么知道呢?
PS start_ap.sh starts the hostapd and that's why it needs killing for next executions. PS start_ap.sh启动hostapd,这就是为什么它需要终止才能进行下一次执行。
You need to run ./start_ap.sh
in the background, then kill it after ./tst.sh
completes. 您需要在后台运行
./start_ap.sh
,然后在./tst.sh
完成后将其杀死。 Note that if you actually run the script as root, there is no need to use sudo
inside the script. 请注意,如果您实际上以root用户身份运行脚本,则无需在脚本内部使用
sudo
。
for run in {1..11}; do
./start_ap.sh & pid=$!
sleep 10
./tst.sh
kill "$pid"
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.