Solved

Problem in using nohup command

Posted on 2006-07-05
11
982 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Title # Comments Views Activity
ASCII Non-Printable characters/codes and their HTML equivalents 6 130
sameEnds challenge 3 180
while loop over for loop 7 115
sum28 challenge 31 115
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

839 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