|
Home > Archive > Unix Shell > October 2006 > how to write a bash script to do the following tasks?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
how to write a bash script to do the following tasks?
|
|
| yangliang_mr@hotmail.com 2006-10-22, 7:19 pm |
| Hi,
I need to run a server program (SVR) on machine A and a client program
(CLI) on machine B. To set up a connection between SVR and CLI, the
following command must be issued on machine B:
$CLI -connect A -name link1
After the connection is set up between A and B, the Client program will
show a message -- "Connection is set up" on the screen. Then I will let
the server program do some real work on machine A (no external input
needs to be taken for the client program during this process on machine
B).
I need to set up many connections between A and B, i.e. I have to spawn
multiple instances of the client program. The server can only take one
connection request from the client program at one time, otherwise the
server program will refuse to work (i.e. connection requests has to be
sent out sequentially on machine B).
I'm trying to run the following bash script file on B (server program
is always running on A):
CLI -connect A -name link1 &
CLI -connect A -name link2 &
CLI -connect A -name link3 &
CLI -connect A -name link4 &
....
CLI -connect A -name link100 &
I got two problems:
Problem1: How to simulate the action pressing ENTER key in the bash
script file?
Explanation: even though I append & to each command line in the script
file, the task is not put into background automatically after the first
connection is set up. This is because the shell does not get the
control back from the client program and thus all the following command
lines do not get a chance to execute. I have to press ENTER key when
the message "Connection is set up" shows up. To confirm this, I
type the single command line "CLI -connect A -name link1 &" in
the shell and got the same thing (shell prompt does not come back
immediately unless I press ENTER key after the message "Connection is
set up" shows up on the screen)
Problem2: How to spawn the client program both in background and
sequentially?
Explanation: As the connection request has to be issued sequentially,
if I put all those tasks into background, I can not control the
sequence of connection request from so many client programs to the
server program. I try to put the semicolon before or after & to force
those tasks to run one by one. But the shell complains about the
combination use of semicolon (;) and background task symbol (&).
Can anyone help me solve this issue?
Thanks,
Liang
| |
| Chris F.A. Johnson 2006-10-22, 7:19 pm |
| On 2006-10-22, yangliang_mr@hotmail.com wrote:
>
> I need to run a server program (SVR) on machine A and a client program
> (CLI) on machine B. To set up a connection between SVR and CLI, the
> following command must be issued on machine B:
> $CLI -connect A -name link1
Please do not multipost. If you feel an article belongs in more
than one group, cross-post, i.e., put all the groups on the
newsgroups line. If this is not possible with the interface you are
using, either confine the post to a single group, or use a real
newsreader to post articles.
Your question has been answered in one of the other groups to which
you posted.
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
|
|
|
|
|