0

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?

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

2
  • 1
    I haven't understood a thing you ask. Maybe the first thing you can try is to not need to C-c start_ap.sh in the first place? Commented Apr 25, 2017 at 21:58
  • If you have to run the script as root, why run sudo later? Commented Apr 25, 2017 at 22:25

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer. Unfortunately, it does not kill the process. May be there is a way to find the name of process and kill it. In htop it is possible to filter out the name that can be seen under the command raw. Any ideas?
@MarkDelphi Without more information about start_ap.sh and hostapd and their process structure etc it's really hard to make suggestions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.