How to emulate terminals waiting for commands ?

How to emulate terminals waiting for commands ?

Post by Bian, Yin » Tue, 23 Mar 2004 21:27:09



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?

 
 
 

How to emulate terminals waiting for commands ?

Post by Chris F.A. Johnso » Fri, 26 Mar 2004 04:41:23



> 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