简体   繁体   中英

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.

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.

So far, after execution of sudo ./start_ap.sh, the next lines will not be executed without killing its process.

How can I realize it?

PS start_ap.sh starts the hostapd and that's why it needs killing for next executions.

You need to run ./start_ap.sh in the background, then kill it after ./tst.sh completes. Note that if you actually run the script as root, there is no need to use sudo inside the script.

for run in {1..11}; do
    ./start_ap.sh & pid=$!
    sleep 10
    ./tst.sh
    kill "$pid"
done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM