Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 10-10-2005, 11:37 AM   #1
LQ Newbie
Registered: Oct 2005
Location: rom,italy
Distribution: redhat,fedora,AIX
Posts: 24

Rep: Reputation: 15
nohup retuncode

Can sombody tell me if it's possible to get the returncode from a script that is launched with nohup...


echo test
exit 8

script launch test
nohup 1>test.log 2 >1 &
echo $rc >rc

if i try so a don't get the return code because nohup run the script in other shell, is there smome way to do this ???

sorry for my bad english
Old 10-11-2005, 08:19 AM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,986
Blog Entries: 14

Rep: Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187
Your English is fine.

The issue is that you're sending this a background process with the ampersand ("&"). The nohup just tells it not to hang up when the terminal goes away so doesn't really have anything to do with backgrounding it.

By definition any process started with "&" will give the shell that started it a return code of 0 (success) because the "&" has told the starting shell not to wait for return status.

What you could do is have a another script that executes and then records its return code. Within that script you would NOT background However you WOULD background that new script.

It would be simpler though to just incorporate whatever action you want to take within itself at the point it is doing its return code. If you just want to know what it did you can just have it output the return code to a file then check that file manually. You could even have it redirect its output to your live terminal but if you're doing that you shouldn't do "nohup" as it will have issues if it tries to output to the terminal and you've logged out and closed the terminal.

Last edited by MensaWater; 10-12-2005 at 12:23 PM.
Old 10-13-2005, 06:04 AM   #3
LQ Newbie
Registered: Oct 2005
Location: rom,italy
Distribution: redhat,fedora,AIX
Posts: 24

Original Poster
Rep: Reputation: 15

Thanks, your solution works fine.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nohup and Background Jobs Onyx2316 Linux - Newbie 3 02-28-2012 12:10 AM
help on nohup vinayuh Linux - General 3 07-22-2005 12:24 PM
nohup command chbin Slackware 1 03-31-2005 03:47 AM
How to nohup an already running program ? fluppi Linux - General 0 06-29-2004 03:47 AM
nohup failure tn1681 Programming 1 01-09-2003 05:40 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:13 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration