1

Do long running bash scritps close themselves after a while? That is do they timeout? I have tried searching this seemingly simple question but can't seem to find the answer.

I am running a bash script over night in order to gather data but my script stops running by morning.

My scripts looks something like this:

#!/bin/bash
port="3000"
host="192.168.1.1"
(
for(( y=0; y<225; y++))
do
    for(( x=0; x<79; x++ ))
    do
    sleep 3
    echo "command1"
    sleep 35
    done
echo "command2"
sleep 300
done
) | telnet "${host}" "${port}" | tee -a -i outputFile

I'm not sure if the problem could be related to my output file either. Currently my output file has over 100 000 lines.

Any advice or direction would be much appreciated.

9
  • 1
    bash is the wrong tool. You should use expect.
    – waltinator
    May 30, 2019 at 23:02
  • 4
    The script will finish after about eight and a half day. (((35+3)×79)+300)×225=742,950 seconds and the for-loops are done.
    – mook765
    May 30, 2019 at 23:20
  • I would be using expect but I do not have administrative powers on the machine I am using so I was unable to install it. I am reduced to using bash. Woe is me. I am quite happy with the bash script though. It does it's job if only it would run over night. Do you know if bash timesout after a certain amount of time?
    – LittleDice
    May 31, 2019 at 0:02
  • bash does not time out, what could time out is the telnet connection ( if so configured, but I am no telnet expert to know for sure ). IMHO if you do need to have something running overnight, start a screen or tmux session or the remote machine. Tmux and screen have learning curve for attaching and detaching sessions but they work wonders once you are used to them. May 31, 2019 at 0:10
  • Mook: My problem is that the script doesn't run for 8 days. I would love it if it did. But it won't. Do you know if bash times out?
    – LittleDice
    May 31, 2019 at 0:12

0

You must log in to answer this question.

Browse other questions tagged .