Execute Script using nohup and &


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute Script using nohup and &
# 1  
Old 03-30-2009
Execute Script using nohup and &

Hi all,

I have one script test.sh for which I pass two arguments. In the same script I need to submit this script in background using nohup. My script like this and it is working in HP-UX os but not Solaris.

Code:
#! /bin/sh

if [ $MTR_PID"0" = "0" ]
then
	MTR_PID=$$
	export MTR_PID
	echo "test.sh $1 $2 $MTR_PID"|xargs nohup |&
fi

if [ $3"0" != "0" -a "$3" = "$MTR_PID" ]
then
        while [ 1 ]
                do
			./Monitor.sh $1
                        sleep $2
                done
fi
exit

Can anyone tell me why this is not getting executed in Solaris?

Thanks,
Sridhar
# 2  
Old 03-30-2009
As you only have a limited number of arguments to your test.sh script I would replace:
Code:
echo "test.sh $1 $2 $MTR_PID"|xargs nohup |&

with:
Code:
nohup test.sh $1 $2 ${MTR_PID} &

instead, perhaps being a bit simpler it will then behave running on both HP-UX and Solaris?

Also Monitor.sh is preceded with "./" should test.sh also be preceded with "./", which it will need if test.sh is not in the PATH and is in the current directory?
# 3  
Old 03-31-2009
Hi Tony,

Your suggestion worked!! I was not knowing that we can pass arguments while using nohup as well.
Thanks a lot

I kept like this now.
Code:
nohup test.sh $1 $2 ${MTR_PID} >> mtr.log 2>> mtr.log </dev/null &

in order to redirect the output and errors to mtr.log. But when this is executed, its still creating nohup.out file with 0 size. How can I avoid the creation of nohup.out file?

Thanks,
Sridhar
# 4  
Old 03-31-2009
I don't know if you can avoid a nohup.out file (except by doing a cd /tmp and then calling your script with a full path so that nohup.out ends in in /tmp?) but I do know that:
Code:
>> mtr.log 2>> mtr.log

can be replaced with:
Code:
>> mtr.log 2>&1

The 2>&1 combines stderr with stdout so that both get appended to mtr.log.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Nohup with ampersand & process gets disconnected

For years I have spawned shell scripts with nohup and ampersand and they run whether or not I stay logged in. Recently a client told us that we had to set a keep alive timeout on all of our Redhat 7.6 Linux servers. Our sysadmin set the following parameters in the sshd_config file on all of our... (10 Replies)
Discussion started by: gandolf989
10 Replies

2. Shell Programming and Scripting

Execute script in Folder with Lower & Upper case

My script test.sh requires an argument and it could be present on a list of servers under a folder with name either in upper or lower case like below: For example: i want a generic command for calling the test.sh script and pass one argument Below is what i tried but it is failing ... (10 Replies)
Discussion started by: mohtashims
10 Replies

3. UNIX and Linux Applications

Execute Oracle pl/sql commands in a scrit using nohup

Good afternoon: I need your help please, Im new at Unix nd specially Unix applicationas like oracle and Ive got this problem: I was asked to execute the next script using nohup in order to not hang up the session because it was supposed to connect to the database and then insert about 2... (3 Replies)
Discussion started by: alexcol
3 Replies

4. UNIX for Dummies Questions & Answers

Difference between & and nohup &

Hi All, Can anyone please help me understanding what the difference between the below two? 1. script.sh & 2. nohup script.sh & (2 Replies)
Discussion started by: Anupam_Halder
2 Replies

5. UNIX for Dummies Questions & Answers

How to get a timestamp when running nohup & from a shell?

Hi, I am running nohup cp & in a shell script. How do I get a timestamp so I can get a timing of how long the copy took? Roughly, the script does something like below: date nohup cp -rp /files/source /files/target & date I am mainly wanting to know how long it took for the... (9 Replies)
Discussion started by: newbie_01
9 Replies

6. Linux

How to execute nohup cmd

Hi, nohup sar -u 10 $COUNT | awk 'NR>2 {$2=$4=$7="";}1' | tr -s ' ' '\t' 2>/dev/null >sar.out & i have execute above line from shell script .. but sar.out is created with ZERO bite size.. Help on that what is the problem here Thx, Mani (0 Replies)
Discussion started by: Mani_apr08
0 Replies

7. Shell Programming and Scripting

how do i execute nohup and background job inside the korn script for db2

load_cursor_stmt() { ls /db/admin/ddl/rmn01000/load_cursor*.sql|while read file do echo "${file}" `nohup db2 -tvf "$file" \&` done }Error: ------- /admin/ddl/rmn01000/load_cursor5.sql /db/admin/ddl/rmn01000/load_cursor6.sql + read file + echo... (3 Replies)
Discussion started by: Hangman2
3 Replies

8. UNIX and Linux Applications

nohup and & versus functions

when i have a function definition and function call in my script , i am unable to run my script in background with nohup.. Help me out please..... (3 Replies)
Discussion started by: venugopalsmartb
3 Replies

9. 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

10. UNIX for Dummies Questions & Answers

nohup & mpiexec problems

Hi everyone - I'm trying to start a run of LAMMPS (which takes an input file) with mpiexec on multiple processors. I want to combine this with nohup so that I can log off the node. I've used the syntax below successfully on one cluster, but it doesn't work on the new one I'm using. Any... (0 Replies)
Discussion started by: erin85
0 Replies
Login or Register to Ask a Question