Operating System - HP-UX
1752567 Members
5356 Online
108788 Solutions
New Discussion юеВ

Re: get exit code of a command executed by nohup

 
SOLVED
Go to solution
Paolo Gilli
Frequent Advisor

get exit code of a command executed by nohup

Hi,
I have a script to create a compressed export file from Oracle with this lines:
...
if [ ! -p /tmp/exp_pipe ]; then
mknod /tmp/exp_pipe p
fi
nohup compress $TMP_EXPORTFILE &

exp system/manager file=/tmp/exp_pipe full=y feedback=10000 compress=y direct=y consistent=y >>$TMP_LOGFILE 2>>$TMP_LOGFILE

reading mails sent by crontab, I saw that compress fail with segmentation error, but export run till the end without problem reporting successful completition.

how can I check the exit code of 'compress' command running in background by nohup command?

Thankyou
8 REPLIES 8
Jean-Luc Oudart
Honored Contributor
Solution

Re: get exit code of a command executed by nohup

If you encapsulate the compress command into a script and nohup the script :
script :
compress $TMP_EXPORTFILE
rc=$?
echo "return code for compress " $rc >>

nohup script > script.out 2>&1 &

Regards,
Jean-Luc
fiat lux
Steve Steel
Honored Contributor

Re: get exit code of a command executed by nohup

Hi

Try $? straight after the compress

Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Bill Hassell
Honored Contributor

Re: get exit code of a command executed by nohup

With nohup, you are protecting the process (compress) from being aborted when the parent exits. With &, you separate the process from the parent so naturally there will be no meaningful return code. The reason is that nohup ... & returns immediately to the parent and of course, it will report all is well because the process was started OK. If you need to monitor the success of a background process, you'll need to script it to store a code that can be tested.


Bill Hassell, sysadmin
Arturo Galbiati
Esteemed Contributor

Re: get exit code of a command executed by nohup

Hi Paolo,
a quick solution may be:
nohup compress $TMP_EXPORTFILE 2>errfile &
tail -f errfile

In this way you will see in real time the error coming from the compress

HTH
Art
Bill Hassell
Honored Contributor

Re: get exit code of a command executed by nohup

Just a note about tail -f: it is really designed for a terminal where you watch the monitored data stream, and it runs forever until it is sent a kill signal. In a script, it is quite complicated to handle this condition. Just take stdout and stderr and route them to a file, then check the contents once the compress job is complete. One way to check is to use fuser compressed_file_name.Z and while compression is running, fuser will report the process ID for the compress process, then nothing when it is done.


Bill Hassell, sysadmin
Fred Ruffet
Honored Contributor

Re: get exit code of a command executed by nohup

Don't have time to verify, but doesnt compress hangs on 2Gb files ? How large is your export file ?

If this is the case, you should either pipe to split before compress, or choose an other compress utility such as gzip (which compresses better).

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Paolo Gilli
Frequent Advisor

Re: get exit code of a command executed by nohup

Hello,
thank to all for the answers to my question.
Fred: you are right, compress hangs on 2Gb files(tested on HP-UX 11.0). The oracle istance I have to export, running on Linux RH AS 2.1 and the compress problem occours when the export.Z files size is about 340/360Mb. As you suggested, using gzip instead compress I have no problem but I need to check the result of compress operation.
So as Bill and Jean-Luc wrote, I will script the background process to store a code that can be tested.

Regards
Paolo
Fred Ruffet
Honored Contributor

Re: get exit code of a command executed by nohup

I worked with gzip for a while and had no problem to compress/decompress (no corruption of export file).

If you search for better compression, you should have a look at bzip2, which compresses a bit slower but better than gzip (no corruption problem either)

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)