Operating System - HP-UX
1752806 Members
6281 Online
108789 Solutions
New Discussion юеВ

ksh script - echo to screen even though app is not done

 
SOLVED
Go to solution
Ratzie
Super Advisor

ksh script - echo to screen even though app is not done

I have a script that calls different commands.
And writes to screen.

But the first command, takes about 2 minutes to run, and the script goes on to the next two commands.

I want it to wait until the first command to finish before it goes on to the next, and echo it to the screen.


#!/bin/ksh -p

# Stop the application commands:
echo Disabling xxx application...
/opt/app/application/shutdown
(here is where I want it to wait, or maybe output # every 10 seconds...)
echo xxx application -- disabled
echo


echo Disabling yyy application...
/opt/app/application2/stopapp
echo yyy application -- disabled
echo
8 REPLIES 8
Mark McDonald_2
Trusted Contributor

Re: ksh script - echo to screen even though app is not done

What is in this script:
/opt/app/application/shutdown

Maybe this fires off some background shutdowns and return to you before it is complete.

One method would be to loop and monitor for the processes that are shutting down. Check every 10 seconds and echo the "#" then exit the loop once the processes are gone.

good luck
Suraj K Sankari
Honored Contributor

Re: ksh script - echo to screen even though app is not done

Hi,

As per your script every thing are looks ok. Check your ├в /opt/app/application/shutdown├в script
if your /opt/app/application/shutdown script is having any & which means run the job in background and execute the next line.
So check your /opt/app/application/shutdown script and delete the &

Suraj
Mark McDonald_2
Trusted Contributor

Re: ksh script - echo to screen even though app is not done

Before simply deleting the "&" in the shutdown script, is this an application with lots of processes?

The shutdown script may separately end these processes and removing the "&" will make the script wait for each single process to end before stopping the next process. This could seriously slow the whole process.

A loop in the monitoring script would definitely be better in this case.
Laurent Menase
Honored Contributor

Re: ksh script - echo to screen even though app is not done

if you know the pid of your application and want to check it is still there you can use
while :
do
kill -0 $pid 2>/dev/null||break
sleep 1
done


kill -0 fails if the process doesn't exist anymore
Mark McDonald_2
Trusted Contributor

Re: ksh script - echo to screen even though app is not done

Ratzie

Has this helped? How about some points?
Ratzie
Super Advisor

Re: ksh script - echo to screen even though app is not done

I was looking at possibly...
while
do
ps -ef|grep app
echo #
done

But I dont know the syntax....
James R. Ferguson
Acclaimed Contributor
Solution

Re: ksh script - echo to screen even though app is not done

Hi:

> I was looking at possibly...
> while
> do
> ps -ef|grep app
> echo #
> done

while true
do
PID=$(UNIX95= ps -C app -o pid=)
echo "I see ${PID}"
done

Note the whitespace after UNIX95= . This keeps the setting only for the duration of the command line so that it only applies to the 'ps'. The 'pid=' argument says to suppress a header line and just report the process (if any) whose basename matches "app". This is the truly safe way to find a process by name in HP-UX.

Regards!

...JRF...

Roland Piette
Regular Advisor

Re: ksh script - echo to screen even though app is not done

Hello Ratzie,

Try this following :

PID=`/opt/app/application/shutdown &`
wait $PID

At this step you script will wait until detached process shudown ends.

Good luck,
Roland