Starting and stopping a script after a certain time, from a script
up vote
0
down vote
favorite
I'm new to bash scripting and i have a problem i cannot solve or find the answer to, if this is the wrong place to post then i apologize.
The goal with this script is to check the condition on an external modem(continuously).
#!/bin/bash
set -e
PORT=/dev/ttyUSB0
COUNT=0
read_serial() {
timeout 15 ./test-read.sh 2>&1
sleep 10
}
while true; do
echo "Testing ""AT"" on $PORT for the $COUNT time"
echo -e "atr" > $PORT
read_serial
COUNT=$((COUNT+1))
done
The read script is:
!/bin/bash
set -e
echo "Reading from serial port"
cat -v < /dev/ttyUSB0
wait
What i'm trying to do is send a simple "at", then start another script that reads the output, close that script. Then the idea is to check if the modem responds "OK" or "ERROR". I could get this working by creating two scripts but that feels messy.
So my questions are:
1. Is it possible to start another script, from a script for a short period of time? When i run it, timeout shuts the whole thing down.
2. Is this approach wrong?
Best Regards,
Willie
linux bash timeout
add a comment |
up vote
0
down vote
favorite
I'm new to bash scripting and i have a problem i cannot solve or find the answer to, if this is the wrong place to post then i apologize.
The goal with this script is to check the condition on an external modem(continuously).
#!/bin/bash
set -e
PORT=/dev/ttyUSB0
COUNT=0
read_serial() {
timeout 15 ./test-read.sh 2>&1
sleep 10
}
while true; do
echo "Testing ""AT"" on $PORT for the $COUNT time"
echo -e "atr" > $PORT
read_serial
COUNT=$((COUNT+1))
done
The read script is:
!/bin/bash
set -e
echo "Reading from serial port"
cat -v < /dev/ttyUSB0
wait
What i'm trying to do is send a simple "at", then start another script that reads the output, close that script. Then the idea is to check if the modem responds "OK" or "ERROR". I could get this working by creating two scripts but that feels messy.
So my questions are:
1. Is it possible to start another script, from a script for a short period of time? When i run it, timeout shuts the whole thing down.
2. Is this approach wrong?
Best Regards,
Willie
linux bash timeout
I don't think this approach is wrong, as long as you're getting the result you're after. However - in my experience simple is best. Are you doing this for monitoring purposes? In which case this can be simplified withcron
. There is no reason that you couldn't execute the commands in yoursecond
script within yourfirst
script. Ultimately if you're getting certain output that you want to conditionally action -if
andcase
would do the job for you.
– itChi
Nov 7 at 15:25
Yes it is for monitoring, the serial interface sometimes "freezes" and i would like to know when that occurs. I put the second script in a function thank you!
– Willie Wiholm
Nov 9 at 14:34
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm new to bash scripting and i have a problem i cannot solve or find the answer to, if this is the wrong place to post then i apologize.
The goal with this script is to check the condition on an external modem(continuously).
#!/bin/bash
set -e
PORT=/dev/ttyUSB0
COUNT=0
read_serial() {
timeout 15 ./test-read.sh 2>&1
sleep 10
}
while true; do
echo "Testing ""AT"" on $PORT for the $COUNT time"
echo -e "atr" > $PORT
read_serial
COUNT=$((COUNT+1))
done
The read script is:
!/bin/bash
set -e
echo "Reading from serial port"
cat -v < /dev/ttyUSB0
wait
What i'm trying to do is send a simple "at", then start another script that reads the output, close that script. Then the idea is to check if the modem responds "OK" or "ERROR". I could get this working by creating two scripts but that feels messy.
So my questions are:
1. Is it possible to start another script, from a script for a short period of time? When i run it, timeout shuts the whole thing down.
2. Is this approach wrong?
Best Regards,
Willie
linux bash timeout
I'm new to bash scripting and i have a problem i cannot solve or find the answer to, if this is the wrong place to post then i apologize.
The goal with this script is to check the condition on an external modem(continuously).
#!/bin/bash
set -e
PORT=/dev/ttyUSB0
COUNT=0
read_serial() {
timeout 15 ./test-read.sh 2>&1
sleep 10
}
while true; do
echo "Testing ""AT"" on $PORT for the $COUNT time"
echo -e "atr" > $PORT
read_serial
COUNT=$((COUNT+1))
done
The read script is:
!/bin/bash
set -e
echo "Reading from serial port"
cat -v < /dev/ttyUSB0
wait
What i'm trying to do is send a simple "at", then start another script that reads the output, close that script. Then the idea is to check if the modem responds "OK" or "ERROR". I could get this working by creating two scripts but that feels messy.
So my questions are:
1. Is it possible to start another script, from a script for a short period of time? When i run it, timeout shuts the whole thing down.
2. Is this approach wrong?
Best Regards,
Willie
linux bash timeout
linux bash timeout
asked Nov 7 at 13:32
Willie Wiholm
1
1
I don't think this approach is wrong, as long as you're getting the result you're after. However - in my experience simple is best. Are you doing this for monitoring purposes? In which case this can be simplified withcron
. There is no reason that you couldn't execute the commands in yoursecond
script within yourfirst
script. Ultimately if you're getting certain output that you want to conditionally action -if
andcase
would do the job for you.
– itChi
Nov 7 at 15:25
Yes it is for monitoring, the serial interface sometimes "freezes" and i would like to know when that occurs. I put the second script in a function thank you!
– Willie Wiholm
Nov 9 at 14:34
add a comment |
I don't think this approach is wrong, as long as you're getting the result you're after. However - in my experience simple is best. Are you doing this for monitoring purposes? In which case this can be simplified withcron
. There is no reason that you couldn't execute the commands in yoursecond
script within yourfirst
script. Ultimately if you're getting certain output that you want to conditionally action -if
andcase
would do the job for you.
– itChi
Nov 7 at 15:25
Yes it is for monitoring, the serial interface sometimes "freezes" and i would like to know when that occurs. I put the second script in a function thank you!
– Willie Wiholm
Nov 9 at 14:34
I don't think this approach is wrong, as long as you're getting the result you're after. However - in my experience simple is best. Are you doing this for monitoring purposes? In which case this can be simplified with
cron
. There is no reason that you couldn't execute the commands in your second
script within your first
script. Ultimately if you're getting certain output that you want to conditionally action - if
and case
would do the job for you.– itChi
Nov 7 at 15:25
I don't think this approach is wrong, as long as you're getting the result you're after. However - in my experience simple is best. Are you doing this for monitoring purposes? In which case this can be simplified with
cron
. There is no reason that you couldn't execute the commands in your second
script within your first
script. Ultimately if you're getting certain output that you want to conditionally action - if
and case
would do the job for you.– itChi
Nov 7 at 15:25
Yes it is for monitoring, the serial interface sometimes "freezes" and i would like to know when that occurs. I put the second script in a function thank you!
– Willie Wiholm
Nov 9 at 14:34
Yes it is for monitoring, the serial interface sometimes "freezes" and i would like to know when that occurs. I put the second script in a function thank you!
– Willie Wiholm
Nov 9 at 14:34
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53190484%2fstarting-and-stopping-a-script-after-a-certain-time-from-a-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I don't think this approach is wrong, as long as you're getting the result you're after. However - in my experience simple is best. Are you doing this for monitoring purposes? In which case this can be simplified with
cron
. There is no reason that you couldn't execute the commands in yoursecond
script within yourfirst
script. Ultimately if you're getting certain output that you want to conditionally action -if
andcase
would do the job for you.– itChi
Nov 7 at 15:25
Yes it is for monitoring, the serial interface sometimes "freezes" and i would like to know when that occurs. I put the second script in a function thank you!
– Willie Wiholm
Nov 9 at 14:34