Solved

Problem in using nohup command

Posted on 2006-07-05
11
978 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

15 Experts available now in Live!

Get 1:1 Help Now