0

I think what I want to do is fairly simple; I would like to limit the total runtime of my callSite function to only x seconds; as I only want it to run, not necessarily connect. That part is being handled in a later part of my project.

I think what I would need to do is kill the process of callSite however I am running into some issues with doing that when using a timer as a loop that's being run in parallel.

    #!/usr/bash
    function timer {
            for ((i=$1; i>0; i--)); do
            printf "\rScript will finish in $i seconds."
            read -s -n 1 -t 1 key
            if [[ $key ]]
            then
                break
            fi
        done

}

function callSite {
      sudo minicom Cisco -d $1
      #configuration for the modem dialing program
}



 timer 60 & callSite Boston && fg
 #this is where one would enter the desired runtime of the process

What would you suggest I do to tie the timer and the minicom together so that the minicom process is killed once the specified amount of time has passed?

rwaweber
  • 113
  • 1
  • 8
  • possible duplicate of [execute function with timeout](http://stackoverflow.com/questions/9954794/execute-function-with-timeout) – Emilien Jun 24 '14 at 14:30
  • It actually depends on how you do `#configuration for the modem dialing program`. – konsolebox Jun 24 '14 at 14:39
  • @konsolebox the only configuration I have stored for the modem dialing program is just the serial port the program is mapped to. I'm declaring it as a function so that way I don't have to call the command each time in my script as I plan on replicating it several times within the same script to dial out to different sites. – rwaweber Jun 24 '14 at 14:46
  • @Emilien thank you! I was able to to get what I wanted through using the timeout command. – rwaweber Jun 24 '14 at 14:52
  • @rwaweber What I mean is that wouldn't `sudo minicom Cisco -d $1` run on foreground and stop the script before you get to run commands after it? – konsolebox Jun 24 '14 at 14:58

1 Answers1

0
(
    callSite Boston &
    PID=$!
    timer 60 && kill "$PID" &>/dev/null
) &
konsolebox
  • 72,135
  • 12
  • 99
  • 105
  • I was able to accomplish the same thing by using the timeout command as follows(while root): timeout 60s minicom Cisco -d Boston – rwaweber Jun 24 '14 at 14:54