Cleverson
Cleverson

Reputation: 5

Keep a script running through ssh after logout

This is the first question that I post here. I tried to do a throughout search, but if I haven't (and the answer is obvious somewhere else), please just let me know.

I have a script that runs a program for me, here it is:

csv_file=../data/teste_nohup.csv
trace_file=../data/gnp.trace

declare -i n=100
declare -i p=1
declare -i counter=0

while [ $counter -lt 3 ];
do
n=100    
    while true
    do
      nice -19 sage gnptest.py ${n} ${p} | tee -a ${csv_file}
      notify-send "finished test gnp ${n} ${p}"
    done
done

So, what I'm trying to do is run the gnptest.py program a few times, and have the result be written to the csv_file.

The problem is, that depending on the input, the program may take a long time to complete. So I'd like to connect to the server over ssh, start the program, close the terminal, and check the output file from time to time. I've tried nohup and disown. Nohup creates a huge nohup.out file, full with errors that I don't get while normally running the script (it complains about using the -lt operand, for example). But the biggest problem that I'm facing is that no command (nohup ou disown -h) is executing the program and sending the output to the file that I've specified in the csv_file variable, which is being done using the tee command. Also, none of them seem to continue running after I logout...

Any help will be much appreciated.

Thanks in advance!!

Upvotes: 0

Views: 1321

Answers (1)

PradyJord
PradyJord

Reputation: 2160

i hv just joined so cannt add comment

Please try by using redirection instead of tee in script And to get rid of Nohup.out use following to run script nohup script.sh > /dev/null 2>&1 &

If above produces error use

nohup script.sh > /dev/null 2>&1 </dev/null &

Hope this will help.

Upvotes: 1

Related Questions