Page 1 of 1

Using mkdbfile in a Unix script - foreground & backgroun

Posted: Tue Apr 16, 2013 5:19 pm
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 ?

Posted: Tue Apr 16, 2013 5:50 pm
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?

Posted: Tue Apr 16, 2013 6:25 pm
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 &"

Posted: Tue Apr 16, 2013 8:05 pm
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?

Posted: Tue Apr 16, 2013 11:44 pm
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.

Posted: Wed Apr 17, 2013 3:01 am
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

Posted: Wed Apr 17, 2013 7:27 am
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.

Posted: Wed Apr 17, 2013 7:30 am
by chulett
Googled for your signal and found this, perhaps helpful?

Posted: Wed Apr 17, 2013 7:35 am
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:

Posted: Wed Apr 17, 2013 8:22 am
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