Tech Support > Computers & Technology > Programming > how to simulate press "spacebar, enter, esc keys" at the unix shell (sh, ksh) script???
how to simulate press "spacebar, enter, esc keys" at the unix shell (sh, ksh) script???
Posted by standardhk@gmail.com on May 9th, 2007


i have a script called "script1.sh" for auto-telnet to a cisco router
and printout the "show run" as below:

#!/bin/ksh
(
echo cisco
sleep 1
echo en
sleep 1
echo cisco
sleep 1
echo show run
sleep 5
echo exit
sleep 3
) | telnet 192.168.0.1

then I run
# ./script1.sh > script1.log
however the "show run" cannot fully display, becuase it require to
press "spacebar"

so how can i simulate "press spacebar" at the script???

thanks
steve

Posted by Ico on May 9th, 2007


standardhk@gmail.com wrote:
Try something like

echo -n " "

The -n flag tells echo not to issue a newline after the string.

Chances are that this will not work properly because of problems with
line buffering, but you can give it a try.

--
:wq
^X^Cy^K^X^C^C^C^C

Posted by Ben C on May 9th, 2007


On 2007-05-09, standardhk@gmail.com <standardhk@gmail.com> wrote:
Use expect. http://expect.nist.gov/

Posted by standardhk@gmail.com on May 10th, 2007


On 5¤ë9¤é, ¤U¤È6®É28¤À, Ben C <spams...@spam.eggs> wrote:
expect can do it ? but how ?


Posted by Steve O'Hara-Smith on May 10th, 2007


On 9 May 2007 21:52:58 -0700
standardhk@gmail.com wrote:

putchar (' ') or thereabouts - download it and look at the source.

--
C:>WIN | Directable Mirror Arrays
The computer obeys and wins. | A better way to focus the sun
You lose and Bill collects. | licences available see
| http://www.sohara.org/

Posted by Ben C on May 14th, 2007


On 2007-05-10, standardhk@gmail.com <standardhk@gmail.com> wrote:
Something like this, details and other things probably wrong:

#!/usr/bin/expect
set timeout -1

# Some pattern that matches your prompt
set prompt "$ *"

spawn telnet 192.168.0.1

foreach cmd {cisco en cisco "show run"} {
expect $prompt
send $cmd\r
}

expect "press spacebar*"
send " "

expect $prompt
send exit\r

close
wait

No dodgy sleeping-- expect waits for the proper response and then sends
the next thing. And it can interact properly with a terminal program,
whereas your script just writes to stdin.

The programming language here is actually Tcl and if you need more help
with it, comp.lang.tcl is very good.

Posted by STandard on May 17th, 2007


On 5¤ë15¤é, ¤W¤È5®É06¤À, Ben C <spams...@spam.eggs> wrote:
thanks Ben, I will try


Posted by arjen@frizone.nl on May 17th, 2007


Disable --More--:

On 9 mei, 08:50, standar...@gmail.com wrote:
sleep 1


Posted by STandard on May 18th, 2007


On 5¤ë18¤é, ¤W¤È12®É18¤À, a...@frizone.nl wrote:
oh it's great
thanks