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










share|improve this question






















  • 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















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










share|improve this question






















  • 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













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










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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


















  • 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
















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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini