Solved

Problem in using nohup command

Posted on 2006-07-05
11
981 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET how to use the Vertical ScrollBar 5 103
List out all word 7 289
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 250
Way to decrease size of apk file 9 65
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: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

775 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