Using mkdbfile in a Unix script - foreground & backgroun
Moderators: chulett, rschirm, roy
Using mkdbfile in a Unix script - foreground & backgroun
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 ?
Anyone know if anything special has to be done to get this command working successfully in background ?
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
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?
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?
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Hi,
You might try this one (if your shell supports disown)
Eric
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
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.
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.
Googled for your signal and found this, perhaps helpful?
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
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.....
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.....
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)
Still, depending on your shell it might not work.
Eric
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
Eric