Solved

Problem in using nohup command

Posted on 2006-07-05
11
979 Views
Last Modified: 2013-12-26
Hi All,

The OS I am using is Solaris 8.

In my developed script, I use the nohup command to run another script as a background job.

After issuing this nohup command, my script continue to process the remaining script.

While my script is still running (after issuing the nohup command), I press the Ctrl+C many times at the terminal, I found sometimes the script run with the nohup command was aborted.

Is there any bug with the nohup command?
Please advise.
0
Comment
Question by:ee_lcpaa
  • 6
  • 5
11 Comments
 
LVL 38

Expert Comment

by:yuzh
ID: 17047855
When you use "nohup" you should run the command/script in the backgroud, eg:

nohup command [args] &

You could also specify a log file to log the process, eg:

nohup  `/path-to/script args` /path-to/logfile &

man nohup
to learn more details
0
 

Author Comment

by:ee_lcpaa
ID: 17047993
Dear yuzh,

I use the nohup command as follows:

nohup anotherscript > $RESULT_FILE 2>&1 &


But I found the script anotherscript may be aborted sometimes when I press CTRL+C at the terminal.

Please advise.
0
 
LVL 38

Expert Comment

by:yuzh
ID: 17048275
try:

nohup `anotherscript > $RESULT_FILE 2>&1` &
0
 

Author Comment

by:ee_lcpaa
ID: 17048459
Dear yuzh,

When I tried this

nohup `anotherscript > $RESULT_FILE 2>&1` &

The error popped up

usage: nohup command arg

Please advise.
0
 
LVL 38

Expert Comment

by:yuzh
ID: 17056763
Are you runing
nohup anotherscript > $RESULT_FILE 2>&1 &
 
inside a script?
if it is the case, when you type in Ctrl C, it will kill the parent script.

Conside use nohup to run your parent script, and use "trap" to make the script
keep going when you type in "Ctrl C"

Please have a look at the example in:
http:Q_20311700.html

PS: back quote doesn't work with nohup in Solaris.

Have a nice weekend!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:ee_lcpaa
ID: 17096365
Hi yuzh,

I've used the command trap " " 1 2 3 to trap the Ctrl C signal.

However, I found sometimes the script was stopped running if I pressed Ctrl + C many times.

What is the reason about this?
0
 
LVL 38

Expert Comment

by:yuzh
ID: 17097705
It depends on what you trap. if you want to complete the whole script, you should
definde the script as a function

and use trap to run the function in the Main body, see the example in:
http:Q_20311700.html#7084988
0
 

Author Comment

by:ee_lcpaa
ID: 17105909
Dear yuzh,

Besides trapping the CTRL+C signal, I have a new problem.

In fact, I can run the command below in my terminal manually
nohup mycommand -q "StringA = 'Hello'" -u &

If I try to run this commad in my script, it failed

nohup mycommand $INPUT_ARG &

where $INPUT_ARG= -q "StringA = 'Hello'" -u

same as what I type in the terminal

Please advise.

0
 

Author Comment

by:ee_lcpaa
ID: 17105913
Please note I am suing ksh
0
 

Author Comment

by:ee_lcpaa
ID: 17105918
I wonder it is due to the " character .......
0
 
LVL 38

Accepted Solution

by:
yuzh earned 125 total points
ID: 17106125
It have something to do with the commandline args handling.

It should be:
INPUT_ARG="-q \"StringA = 'Hello'\" -u"

You can put
echo $INPUT_ARG
before nohup to find out what the value is.

Good luck!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now