LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices



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

Rep: Reputation: 15
nohup retuncode


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

example

script test.sh
#!/bin/sh
echo test
exit 8


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


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


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

Rep: Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791
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 test.sh and then records its return code. Within that script you would NOT background test.sh. However you WOULD background that new script.

It would be simpler though to just incorporate whatever action you want to take within test.sh 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 01:23 PM.
 
Old 10-13-2005, 07:04 AM   #3
krusty_lab
LQ Newbie
 
Registered: Oct 2005
Location: rom,italy
Distribution: redhat,fedora,AIX
Posts: 24

Original Poster
Rep: Reputation: 15
Talking

Thanks, your solution works fine.
Christian
 
  


Reply


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 01:10 AM
help on nohup vinayuh Linux - General 3 07-22-2005 01:24 PM
nohup command chbin Slackware 1 03-31-2005 04:47 AM
How to nohup an already running program ? fluppi Linux - General 0 06-29-2004 04:47 AM
nohup failure tn1681 Programming 1 01-09-2003 06:40 PM


All times are GMT -5. The time now is 11:04 PM.

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