Using mkdbfile in a Unix script - foreground & backgroun

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
sec105105
Participant
Posts: 44
Joined: Fri Mar 20, 2009 7:21 am
Location: Ottawa

Using mkdbfile in a Unix script - foreground & backgroun

Post by sec105105 »

I have a Unix(ksh) script that I use to build hash files using mkdbfile. If I run interactively, it works fine. If I run in background (using & ), it either hangs, or times out with a STTY-like error.

Anyone know if anything special has to be done to get this command working successfully in background ?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I don't recall the gory details of that command... when you run it interactively from the command line does it stop and prompt for a response of any kind?
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Try preceding the mkdbfile command with nohup so that its controller can return straight away.

Test this in the Administrator client command window, preceded by SH -c.

Code: Select all

SH -c "nohup $DSHOME/bin/mkdbfile name options &"
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sec105105
Participant
Posts: 44
Joined: Fri Mar 20, 2009 7:21 am
Location: Ottawa

Post by sec105105 »

Hi,

I have tried it within a shell, and also just the base command from the prompt. Same behaviour in a shell, or not. As soon as I tack on the & , it hangs.

chulett - no, when run from command line, finishes on its own without further interaction.

ray - I have tried with nohup. Eg:
nohup mkdbfile {many parameters}
and it's all good.

if I try :
nohup mkdbfile {many parameters} &
it hangs.

I'm using ksh. Can you elaborate on your suggestion, please?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Not really. The trailing & still means "create a background process" in ksh, and the nohup simply specifies not to wait for it to finish. What exactly do you mean by "hangs"? The mkdbfile command works perfectly well in a background process in my experience, provided its syntax is correct.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
eph
Premium Member
Premium Member
Posts: 110
Joined: Mon Oct 18, 2010 10:25 am

Post by eph »

Hi,

You might try this one (if your shell supports disown)

Code: Select all

		trap "true" HUP # Do nothing but run "true" on SIGHUP
		# runs a shell function in the background, with its files redirected
		# the same way nohup does.  & puts it in the background.
		# 'disown' tells the shell not to wait for it on exit.
		# disown isn't available in some shells, but if the shell
		# doesn't have it, it also doesn't need it.
		YOURCOMMAND COMMANDARGS > /dev/null 2> /dev/null < /dev/null & disown
Eric
sec105105
Participant
Posts: 44
Joined: Fri Mar 20, 2009 7:21 am
Location: Ottawa

Post by sec105105 »

eph - tried:
nohup $binDir/mkdbfile $projectDir/tmp_date_ids2 30 34183 4 20 50 80 1639 -32BIT 2>&1 & disown

Got "ksh: disown: not found" (I'm on SunOS).

What I'm seeing is - it just hangs - ie the process just exists (I check from another window), and it seems like there's no cpu allocated:

myuser 10765 3635 0 09:21:36 pts/2 0:00 /opt/IBM/InformationServer/Server/DSEngine/bin/mkdbfile /xxx/yyy/datasta...

Interestingly, if I hit [enter] in the first window, it often comes back with the error:
Stopped (SIGTTOU) nohup $binDir/mkdbfile $projectDir/tmp....

Yet the process does not die (it is still visible in the 2nd window) , and I have to kill -9 it manually.

It's almost as if the command is waiting for terminal or keyboard input.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Googled for your signal and found this, perhaps helpful?
-craig

"You can never have too many knives" -- Logan Nine Fingers
sec105105
Participant
Posts: 44
Joined: Fri Mar 20, 2009 7:21 am
Location: Ottawa

Post by sec105105 »

Doh! That'll learn me not to paraphrase other people's text!

Eric - I later tried:
nohup $binDir/mkdbfile $projectDir/tmp_date_ids2 30 34183 4 20 50 80 1639 -32BIT 2>&1 < /dev/null & disown

And, although I still got the 'disown not found' error, the hashfile seems to have been created!

I then tried:
nohup $binDir/mkdbfile $projectDir/tmp_date_ids2 30 34183 4 20 50 80 1639 -32BIT 2>&1 < /dev/null &

and again, it got created. So, as I speculated above, something about some kind of terminal input was causing a problem ,and redirecting the /dev/null took care of it.

Still testing, but it looks good. Will post again if I run into more roadblocks.

Thanks to all of your suggestions! Now to migrate off theses stupid hashfiles entirely..... :roll:
eph
Premium Member
Premium Member
Posts: 110
Joined: Mon Oct 18, 2010 10:25 am

Post by eph »

It's good to know you have found a working solution. It seems that your command line was waiting for an input (provided here by /dev/null).

As stated in the comment, if your shell doesn't have disown, it probably doesn't need it. And note that with the trap command executed before, you don't need to use nohup

In your case you should have tried (works on RedHat5 ksh and bash)

Code: Select all

trap "true" HUP # Do nothing but run "true" on SIGHUP
# runs a shell function in the background, with its files redirected
# the same way nohup does.  & puts it in the background.
# 'disown' tells the shell not to wait for it on exit.
# disown isn't available in some shells, but if the shell
# doesn't have it, it also doesn't need it.
$binDir/mkdbfile $projectDir/tmp_date_ids2 30 34183 4 20 50 80 1639 -32BIT > /dev/null 2> /dev/null < /dev/null
Still, depending on your shell it might not work.

Eric
Post Reply