2

I want to get the time when program finish. But it always show the same time. Here is my shell script. But it always show that START TIME is same as END TIME.

START=$(date +"%r") nohup Rscript program_1.R >program_1.Rout & wait & echo START TIME = $START\n END TIME = " `date +"%r"`"; 

1 Answer 1

1

The problem is that whenever you delimit a command with & this command executes in the background and the following command will start immediately with the first command and not after it. Your problem is unrelated to nohup (which means that programs that are still running when the parent shell exits should not be killed but continue execution). For your problem try something like

nohup /bin/bash -s <<< "date; your-script.sh ; date " >& all-output.txt & 

This will run your job and output timings in the background and redirect all output to the given file.

BTW, if you are only interested in the runtime, you should do

nohup /bin/bash -s <<< "time your-script.sh " >& all-output.txt & 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.