shell script not working with nohup

Hello, I am trying to run a shell script with the nohup command. The shell script takes an array of files, runs a python program on each file in a loop, and appends the output to a file. This works fine on the server, but if I try to use the nohup command it does not work.

---

#!/bin/sh
ARRAY=(0010.dat 0020.dat 0030.dat)

rm batch_results.dat
touch batch0.dat
touch batch_results.dat

for file in ${ARRAY[@]}
do
python fof.py $file > /dev/null
python mdisk5.py > ./batch0.dat
tail -1 batch0.dat
tail -1 batch0.dat >> batch_results.dat
done

---

The program works fine when I run it while staying connected to the server, for example

./batch.sh > /dev/null &
./batch.sh > ./output.txt &

However, when I try to run it with the nohup command,

nohup ./batch.sh > /dev/null &

if I exit the server and come back the output file (batch_results.dat) does not have any data.

I am sure I am missing some simple fix or command in here. Any ideas?

What does the nohup.out file show?

It does not exist. Generally I redirect to ./output.txt, which is blank, or /dev/null

What happens when you do this:

nohup ./batch.sh &

or this.

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

these also did not work:

nohup ./batch.sh &
nohup ./batch.sh >/dev/null </dev/null &

this gave 'Ambiguous output redirect.':

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

Are you running csh or tcsh? If so, try running from /bin/sh.

I am running csh. I tried nohup /bin/sh batch.sh & and some other variations and it also did not work.

I have used nohup successfully on these servers working with other programs. I routinely use nohup ./Main.out > /dev/null & and will run programs for days.

I am not sure if my shell script isn't working because I am piping the output of multiple python runs to different things or what.

That is correct, that all works in csh, but my comment was in relation to my second suggestion

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

where you got the error. This is because you are running csh. You can only try this from within sh/bash/ksh.

OK, I'm still lost on why my code isn't working in csh though. My code works fine when I run it without nohup and I can run other programs using nohup. Something about my script isn't working with nohup...

Have you tried my suggestion to redirect all input and output streams (which you need to do in another shell)? Another thing you could try is to use /usr/bin/nohup instead of nohup. This would bypass the csh built-in.

I cannot change the shell on the server. I tried /usr/bin/nohup and got the same error.

Note that the program fof.py produces two files that are used as input for mdisk5.py. When I run nohup ./batch.sh on the server it works fine. When I run nohup ./batch.sh & and then exit the server, then when I return these two files are produced, but only for the first input file '0010.dat'. The output files batch0.dat and batch_results.dat remain empty.