shell script not working with nohup


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script not working with nohup
# 1  
Old 02-14-2012
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.

---
Code:
#!/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
Code:
./batch.sh > /dev/null &
./batch.sh > ./output.txt &

However, when I try to run it with the nohup command,
Code:
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?

Last edited by Franklin52; 02-15-2012 at 03:28 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 02-14-2012
What does the nohup.out file show?
# 3  
Old 02-14-2012
It does not exist. Generally I redirect to ./output.txt, which is blank, or /dev/null
# 4  
Old 02-14-2012
What happens when you do this:
Code:
nohup ./batch.sh &

or this.
Code:
nohup ./batch.sh >/dev/null 2>&1 </dev/null &


Last edited by Scrutinizer; 02-14-2012 at 03:38 PM..
# 5  
Old 02-14-2012
these also did not work:
Code:
nohup ./batch.sh &
nohup ./batch.sh >/dev/null </dev/null &

this gave 'Ambiguous output redirect.':
Code:
nohup ./batch.sh >/dev/null 2>&1 </dev/null &


Last edited by Franklin52; 02-15-2012 at 03:29 AM.. Reason: Please use code tags for code and data samples, thank you
# 6  
Old 02-14-2012
Are you running csh or tcsh? If so, try running from /bin/sh.
# 7  
Old 02-14-2012
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cp not working in shell script but running perfectly from shell

Dear All, I have script. Dest="" IFS=' ' for translation in $(echo $MY_MAP) do t1=$(echo $translation | cut -d"=" -f1) t2=$(echo $translation | cut -d"=" -f2| cut -d"," -f1) if then Dest=$UNX/$u_product_path/$u_study_path/$UNXTR/$t2 break; ... (4 Replies)
Discussion started by: yadavricky
4 Replies

2. UNIX for Dummies Questions & Answers

Nohup not working as expected

Hi. I am trying to start a script on my router that will execute even if i log off. To execute the script I write: nohup ./dslconnection > dslstat.out 2>&1 & It starts the job: 21968 admin 1604 S /bin/ash ./dslconnection The problem is that when I log back in the job has been... (6 Replies)
Discussion started by: sebcou
6 Replies

3. Shell Programming and Scripting

Nohup inside shell script

Hi, I want to run another script inside shelll script in nohup mode. let explain. under the same folder ,I have two scripts scrone.sh scrtwo.sh In scrone.sh if then nohup ./scrtwo.sh & echo " Script two has been run correctly" else echo " Exiting from the script" fi If... (3 Replies)
Discussion started by: ckchelladurai
3 Replies

4. Shell Programming and Scripting

How to stop nohup which is working background

Please I have run a background script using nohup please tell me way to stop this. Thanks in Advance (4 Replies)
Discussion started by: mumakhij
4 Replies

5. Shell Programming and Scripting

run shell script under nohup directly [solved]

Hi, i am not able to run the loop in nohup directly. nohup 'for i in $(seq 10); do echo $i;./mscript.sh $i; done' can some one help me how to run this directly in nohup? ---------- Post updated 03-15-12 at 12:20 AM ---------- Previous update was 03-14-12 at 11:59 PM ---------- From... (0 Replies)
Discussion started by: johninweb
0 Replies

6. Shell Programming and Scripting

nohup not working

Hi all, I wrote a scirpt (abc.sh) in which I defined a loop with an interval equal to 1 hour. I want this script continue to run when I close the terminal, so I ran the following command, (in the proper directory) nohup abc.sh However the script doesn't just keep running when I... (1 Reply)
Discussion started by: isaacniu
1 Replies

7. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

8. Shell Programming and Scripting

Perl script 'system' linking to local shell script not working

Trying to figure out why this works: printpwd.pl #!/usr/bin/perl use CGI::Carp qw( fatalsToBrowser ); print "Content-type: text/html\n\n"; $A = system("pwd"); $A = `pwd`; print "$A\n"; ^^actually that works/breaks if that makes any sense.. i get the working directory twice but when... (5 Replies)
Discussion started by: phpfreak
5 Replies

9. Solaris

NOHUP not working

Hello All, Here is a problem of NOHUP. I am trying to run a process which needs to be up and running even if the session is closed. I tried running it with "nohup", but starngely it is not working, when i exit from the session the process is also getting killed? plz help me in finding out... (4 Replies)
Discussion started by: shivamasam
4 Replies

10. Solaris

nohup not working

Hi, I am working in SunOS 5.8. I wanted to run a script in background and I gave the following command, but it is not working. I gave "nohup ksh ULOAD.ksh &" It just came out giving a msg "Redirection or piping of stdin or stdout is allowed only with -b. (156)" in nohup.out file. If I... (2 Replies)
Discussion started by: arsheshadri
2 Replies
Login or Register to Ask a Question