Operating System - HP-UX
1754363 Members
4756 Online
108813 Solutions
New Discussion юеВ

Script run on another shell

 
Fernando Boza
Regular Advisor

Script run on another shell

I have a cluster serviceguard with HP-UX 11.11 and Sybase.

I have a script to start the database whit those lines:

su - sybase -c "/sybase/ASE-12_5/install/startserver -f /sybase/ASE-12_5/install/RUN_SYBASE"
echo "BASE INICIADA"

But.... the messages "BASE INICIADA" appears before base started.

Any idea?
9 REPLIES 9
Steven E. Protter
Exalted Contributor

Re: Script run on another shell

Shalom,

Control the shell the script runs with the top line of the script.

#!/bin/ksh
# Whatever you want.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
TTr
Honored Contributor

Re: Script run on another shell

I can not test it right now but the "startserver" is a binary that detaches from the shell and runs in the background. So the execution continues immediately with the "echo" line while the startserver still running in the background and starts the databases. You can try puting the "echo" inside the "su -c" command as in
"su - sybase -c "/sybase/ASE-12_5/install/startserver -f /sybase/ASE-12_5/install/RUN_SYBASE; echo 'BASE INICIADA'
" but I don't think it will help.
Basheer_2
Trusted Contributor

Re: Script run on another shell

I think this is wahts happening. your startserver script runs in background. it forks a process and then does echo "BASE INICIADA" doesn't wait for the completion of startserver.

you can do this to avoid. change the above line to look like this

su - sybase -c "/sybase/ASE-12_5/install/startserver -f /sybase/ASE-12_5/install/RUN_SYBASE" && echo "BASE INICIADA"

i.e if the startserver scripts runs successfully then do the echo
Suraj K Sankari
Honored Contributor

Re: Script run on another shell

Hi,

Put this in one line with ";" seperator

su - sybase -c "/sybase/ASE-12_5/install/startserver -f /sybase/ASE-12_5/install/RUN_SYBASE";echo "BASE INICIADA"

Suraj
Dennis Handly
Acclaimed Contributor

Re: Script run on another shell

>Suraj: Put this in one line with ";" separator
su - sybase -c "/sybase/ASE-12_5/install/startserver \
-f /sybase/ASE-12_5/install/RUN_SYBASE"; echo "BASE INICIADA"

I don't see how this is any different, than separate su then echo.

I suppose you could do both under that su but that won't be different, other than which shell does the echo.

Suraj K Sankari
Honored Contributor

Re: Script run on another shell

Hi Dennis,

If I give command saperater between 2 commands for example #ls;cat abc

cat abc will run after compleated the 1st command right if this is ok then in above also right 1st it will run the su then it will run echo.

Suraj
Dennis Handly
Acclaimed Contributor

Re: Script run on another shell

>Suraj: If I give command separator between 2 commands for example #ls; cat abc

There is no difference here between ";" and a newline.

>it will run the su then it will run echo.

Yes, they are done in order but there is another process involved. Since the author said it didn't work, and TTr mentioned "background" the ";" won't help.

Peter Nikitka
Honored Contributor

Re: Script run on another shell

Hi,

having a program which puts its execution in background requires an extra monitoring to get the exit status or completion of the background part.

At first try
- measure the time until a connection to the DB succeeds
- write a monitor script which ...
- sleeps that time + some factor
- tries to connect to the DB
- reports the availability of the DB

@Suraj: Your statement is incorrect:
>> #ls;cat abc

>> cat abc will run after compleated the 1st command right
>> if this is ok then in above also right
>> 1st it will run the su then it will run echo.

- You'd have to use
ls && cat abc
to do this. Yours would execute the 'cat' whether the 'ls' succeeds or not.

mfG Peter

The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Bart Paulusse
Respected Contributor

Re: Script run on another shell

Have your script check the startserver process and perform the
echo "BASE INICIADA" after that process is no longer in the processlist.
But... If for some reason the startup of your database fails, you'll still get the "BASE INICIADA" message as if everything is ok.

You say startserver is a binary. How about RUN_SYBASE, if that is a script, you can create your own version of that script and let it mail you upon completion. You could even check for return codes and report a more meaningfull message.

Regards,
Bart