|
Home > Archive > Unix Shell > March 2004 > How to emulate terminals waiting for commands ?
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 emulate terminals waiting for commands ?
|
|
| Bian, Ying 2004-03-22, 7:34 am |
| Hi,
I want to write a interpreter using ksh, the sample
file needs to be interpreted is something like:
========================================
===========
TERM Label1 user1 mach1
TERM Label2 user2 mach2
Label1
uname -a
pwd
... // other Unix commands
Label2
...
Label1
...
========================================
===========
Whenever a line with "TERM" at the beginning is read
from the input, the interpreter should be able to emulate
that someone has logged in some machine and started
a session terminal... Take the line "TERM Label1 user1
mach1" for example, the interpreter will "open" a terminal
for user1 at mach1, and labeling this terminal as "Label1",
waiting for commands input ...
Then, all commands below "Label1" are executed in this
terminal ...
I think Unix shell can meet this need. But I have no
idea. Anyone has a good idea about the implementation
in ksh?
| |
| Chris F.A. Johnson 2004-03-24, 5:23 pm |
| On Mon, 22 Mar 2004 at 12:27 GMT, Bian, Ying wrote:
> Hi,
>
> I want to write a interpreter using ksh, the sample
> file needs to be interpreted is something like:
>
> ========================================
===========
> TERM Label1 user1 mach1
> TERM Label2 user2 mach2
>
> Label1
> uname -a
> pwd
> ... // other Unix commands
> Label2
> ...
> Label1
> ...
> ========================================
===========
>
> Whenever a line with "TERM" at the beginning is read
> from the input, the interpreter should be able to emulate
> that someone has logged in some machine and started
> a session terminal... Take the line "TERM Label1 user1
> mach1" for example, the interpreter will "open" a terminal
> for user1 at mach1, and labeling this terminal as "Label1",
> waiting for commands input ...
>
> Then, all commands below "Label1" are executed in this
> terminal ...
>
> I think Unix shell can meet this need. But I have no
> idea. Anyone has a good idea about the implementation
> in ksh?
SPC=" "
TAB=" "
while IFS= read -r line
do
case $line in
TERM*) open_term ;; ## set up terminal emulation
$SPC*|$TAB*) do_term ;; ## execute line
"") ;; ## empty line: do nothing
*) term=$line ;; ## subsequent lines executed by $term
esac
done < FILE
I don't know just what you mean by "emulate that someone has
logged in", and executing commands in "this terminal", so you need
to write the functions open_term() to set up the terminal, and
do_term() to execute the commands.
Post here with your code and specific problems.
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
|
|
|
|
|