Solved

Problem in using nohup command

Posted on 2006-07-05
11
985 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 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