wait for process to terminate

wait for process to terminate

Post by anju » Thu, 06 Apr 2006 04:10:05



Hi All,

      I checked most of the post to solve this problem. But, I
couldn't.

Here the script,

       Which telnets to another server and run a script and it has to
wait for that script/process to complete.

Script:

#!/usr/bin/ksh

(sleep 5; echo "<uid>"; sleep 10; echo "<passwd>"; sleep 5; echo "<run
script>"; sleep 5;
echo "wait $!"; sleep 2; echo "exit"; sleep 5) | telnet <Server Name> >
tempfile 2> /dev/null

...

Explanation:

$! will give the process ID and with that process ID we can wait until
it completes using the wait on unix machines.

I don't want to do sleep .. want to wait until the process terminates.

OUTPUT:

It's able to login and exceute the <run script> and sleep for 5 sec.
But, it's not waiting (wait $!) for the script to run or process to
complete.

Request:

How can wait until the process terminates. not sleep 10 or sleep 100
only using

 wait PID

Please, Help me to resolve this issue.

Thanks in advance,
an

 
 
 

wait for process to terminate

Post by Bill Marcu » Thu, 06 Apr 2006 05:37:31


On 4 Apr 2006 12:10:05 -0700, anju

> Hi All,

>       I checked most of the post to solve this problem. But, I
> couldn't.

> Here the script,

>        Which telnets to another server and run a script and it has to
> wait for that script/process to complete.

> Script:

> #!/usr/bin/ksh

> (sleep 5; echo "<uid>"; sleep 10; echo "<passwd>"; sleep 5; echo "<run
> script>"; sleep 5;
> echo "wait $!"; sleep 2; echo "exit"; sleep 5) | telnet <Server Name> >
> tempfile 2> /dev/null

> ...

> Explanation:

> $! will give the process ID and with that process ID we can wait until
> it completes using the wait on unix machines.

> I don't want to do sleep .. want to wait until the process terminates.

If for some perverse reason you can't use ssh or rsh, you might try
expect.  Does the telnet connection need to stay alive, or could you
use something like this?
echo "nohup <script> &"

--
Rube Walker: "Hey, Yogi, what time is it?"
Yogi Berra:  "You mean now?"

 
 
 

wait for process to terminate

Post by anju » Thu, 06 Apr 2006 05:56:20


I can Use that "nohup" .. But, i have to with this model only ,, no
expect no ssh no rsh

any other ideas ... Plzzzz

thanks,
an

 
 
 

wait for process to terminate

Post by John DuBo » Thu, 06 Apr 2006 14:06:09




>#!/usr/bin/ksh

>(sleep 5; echo "<uid>"; sleep 10; echo "<passwd>"; sleep 5; echo "<run
>script>"; sleep 5;
>echo "wait $!"; sleep 2; echo "exit"; sleep 5) | telnet <Server Name> >
>tempfile 2> /dev/null
...
>It's able to login and exceute the <run script> and sleep for 5 sec.
>But, it's not waiting (wait $!) for the script to run or process to
>complete.

>Request:

>How can wait until the process terminates. not sleep 10 or sleep 100
>only using

There are much, much better ways of doing such things, but if you *must* use
this telnet method:

You need to create a script that holds open the input file descriptor for
telnet until telnet exits.  There are various ways of doing that, but since
you're using ksh, you can simply use a coprocess and ksh will do the right
thing: wait until telnet exits, then clean up.

#!/usr/bin/ksh
telnet server-name >tempfile 2>/dev/null |&
sleep 5
print -p "<uid>"
sleep 10
print -p "<passwd>"
sleep 5
print -p "<run script>; exit"
wait

        John
--

 
 
 

wait for process to terminate

Post by anju » Thu, 06 Apr 2006 22:03:57


Hi John,

      Thanks for the suggestion.

I would like to print the output of the <run script> or what ever the
script is doing.

Just like not redirecting the output to a temp file .. Just to do it on
to screen. (like remove  >tempfile 2>/dev/null or add | tee etc)

I'm getting the following error if i do the above said.

getwinsize:ioctl: A specified file does not support the ioctl system
call.

what |& means in the 2nd line of Ur script.

Hope U understand my improper english.

Thanks,
an

 
 
 

wait for process to terminate

Post by Chris F.A. Johnso » Fri, 07 Apr 2006 01:42:09



> I would like to print the output of the <run script> or what ever the
> script is doing.

> Just like not redirecting the output to a temp file .. Just to do it on
> to screen. (like remove  >tempfile 2>/dev/null or add | tee etc)

> I'm getting the following error if i do the above said.

> getwinsize:ioctl: A specified file does not support the ioctl system
> call.

   If you posted the script you ran, perhaps someone could help.
   Remember, this is Usenet, NOT a web forum.

Quote:> what |& means in the 2nd line of Ur script.

> Hope U understand my improper english.

   Your Englishn is fine, but U and Ur are not English.

--
   Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
   Shell Scripting Recipes:     |  My code in this post, if any,
   A Problem-Solution Approach  |          is released under the
   2005, Apress                 |     GNU General Public Licence

 
 
 

wait for process to terminate

Post by Bill Marcu » Fri, 07 Apr 2006 02:35:57


On 5 Apr 2006 06:03:57 -0700, anju

> what |& means in the 2nd line of Ur script.

man ksh

--
A * is one who gets paid by the word -- per piece or perhaps.
                -- Robert Benchley

 
 
 

wait for process to terminate

Post by John DuBo » Fri, 07 Apr 2006 08:23:32




>I would like to print the output of the <run script> or what ever the
>script is doing.

>Just like not redirecting the output to a temp file .. Just to do it on
>to screen. (like remove  >tempfile 2>/dev/null or add | tee etc)

Replace >tempfile with >&2 (and optionally remove 2>/dev/null)

Quote:>what |& means in the 2nd line of Ur script.

It runs a pipeline as a coprocess.  See the ksh man page (likewise for an
explanation of >&2).

Also, you should quote any relevant parts of the original message when you post
a followup.

        John
--

 
 
 

wait for process to terminate

Post by anju » Fri, 07 Apr 2006 22:30:26


Quote:>There are much, much better ways of doing such things, but if you *must* use
>this telnet method:
>You need to create a script that holds open the input file descriptor for
>telnet until telnet exits.  There are various ways of doing that, but since
>you're using ksh, you can simply use a coprocess and ksh will do the right
>thing: wait until telnet exits, then clean up.
>#!/usr/bin/ksh
>telnet server-name >tempfile 2>/dev/null |&
>sleep 5
>print -p "<uid>"
>sleep 10
>print -p "<passwd>"
>sleep 5
>print -p "<run script>; exit"
>wait

Hi,

  I could see that the script is waiting to run the "<run script>".

I would like to print the output of the <run script> or what ever the
script is doing.

Just like not redirecting the output to a temp file .. Just to do it on

to screen. (like remove  >tempfile 2>/dev/null or add | tee etc)