Advice needed on using Script with NOHUP

All,

I would like to know my below requirement can be achieved in any way in Shell Scripting? I will make this requirement of mine as understandable as I can.

Requirement:
I wrote a script 'my.script' which gets user-input tablenames and puts the same into an array. Also I get other inputs like logon credentials, Source Database name etc.

I process all the inputs to generate a 'fexp.exec' script on the fly. Then I am trying to execute the 'fexp.exec' script from 'my.script', to start the FastExport process (Teradata Utility to unload the source DB tables to the Unix environment as files). And once 'fexp.exec' script (FastExport) completes, the control returns back to the 'my.script' where I am validating the output files (created from the FastExport) based on the entered input files.

This whole effort is to automate the Unloading of tables from DB to Unix. Before writing the 'my.script', I used to prepare the 'fexp.exec' script manually and run it with a NOHUP (something like the code below), so that i can allow it to run in the background (as FastExport runs for 2 hours).

nohup ksh fexp.exec &

Question:
But now with this effort to automate, I have a requirement to run the 'fexp.exec' script from 'my.script'. And I want the 'fexp.exec' script to be run in the background. Also I do not want to make the my.script run for 2 hours as well!

I know I can just give the above line of code in my 'my.script' file to run the FastExport in the background. But I have the validation of the output files (created from FastExport) based on the entered input files, in 'my.script'. And immediately once after nohup of 'fexp.exec', the validation part in 'my.script' continues and it fails as the output files are not present as the fexp.exec is still running in the background.

To resolve this I see a few ways, but none of them are fruitful. I would need some advise on how to proceed with my condition here!

  1. I can put a wait command after the nohup of fexp.exec, but that would make the my.script to wait for 2 hours, which I dont need.

  2. I can nohup the my.script file itself but the script accepts user-input in various parts of the script.

  3. I tried to echo the validation part into the fexp.exec script after the FastExport commands, so that I can just nohup the 'fexp.exec' and allow the my.script to run to completion once fexp.exec is nohup-ed. For this I have to pass the array that I received in my.script to fexp.exec. But that again is not working. I can post the code for this if you want.

Is there anyother way to achieve my requirement. I am sorry for writing a long story here. Hope I am not confusing anyone. Please let me know if you have any questions. Any help is very greatly appreciated.

p.s: I can post the code for the requirement or the #3 above, if anyone needs it for more understanding. i am not posting the code now just to prevent my post being toooo long :slight_smile:

Thanks
Bharath

So, you want the original process to terminate, while fexp.exec continues to run independently? If you're using the bash shell, the 'disown' command willl tell it not to wait for background processes to return before quitting, but otherwise I don't see why it would be hanging in the first place. It should just quit and let the background process continue.

I do not need the original process to terminate but I would like it to wait in the background for the fexp.exec process (which again runs in the background) to complete and then run the validation part, again in background!

nohup and background the original script when you run it then.

That can be done but I the script 'my.script' accepts user-input in various parts of the script. And when I nohup the parent script, I am not sure of a way of getting user inputs

That's why it hangs then: "waits on various user inputs", if not possible screen chatter to STDOUT. You'll want to refactor the overall interface to the script...but start by reviewing nohup.out in the directory where you'd run the nohup. It would carry the stdout by default...

Perhaps in these user inputs you can include a method to tell it to detach itself? Because you can't have both. You have to close all open file descriptors to the terminal in order to close the connection without hanging on exit or killing the process.

Or you could use a system like screen. Screen keeps around sessions that you can connect to disconnect from, and reconnect to arbitrarily.