Send keystrokes in console mode

Is there any way (or application) to send keystrokes to buffer in console mode on Linux, like some programs do in command line mode on Windows? (i.e. sendkey.exe)
I want to automate some tasks that requires user intervention on my Linux systems, and I already tried to search on the net for something like this, but without success.
I would be greatly thankful if some of you show me a solution.

-------------------------------------------------------------------

I'm afraid I have never seen any program that can do this... it doesn't mean that one doesn't exist though.

Would I be correct to say that you want to be able to effectively run a script in console mode?

Also... I have a question too... I've only ever used console mode on a Sun Solaris machine... is it the same thing on linux?

-------------------------------------------------------------------

By 'console mode', do you just mean a command line interface (ie DOS/Command Prompt, CLI/Shell, etc)?

If so, then the way to do it in most of the commonest CLIs is by using a script and the 'input' redirector ('<'), which tells the shell to use the file immediately following it instead of the console for stdin (i.e. the same as using '>' to redirect stdout).

e.g.

You have generated a file called files.lst
CODE
>more files.lst
dave.jpg
mike.gif
jim.png
bob.ps
>

-------------------------------------------------------------------

Which you have then used a text editor to add the relevant commands necessary for a simple tape program you wish to use

CODE
>more files.lst
friends.tape
dave.jpg
y
mike.gif
y
jim.png
y
bob.ps
n
>
 

and then you just run the desired program
CODE
>tape-it <files.lst
enter tapefile:
enter filename:
adding 'dave.jpg'...
add another?(y/n):
enter filename:
adding 'mike.gif'...
add another?(y/n):
enter filename:
adding 'jim.png'...
add another?(y/n):
enter filename:
adding 'bob.ps'...
add another?(y/n):
creating tapefile 'friends.tape'...
successful.
>

-------------------------------------------------------------------

As a sidenote, the redirectors '>' & '<' were often used in the days before the pipe '|' was available, so a lot of temporary files were created during a 'run'.

Hope some of that is of use.

-------------------------------------------------------------------

Oh, and the '>' that appear at the beginning of a line in the CODE sections are meant to be the CLI's prompt, and not the output redirector.

Oh, you have used 'console mode' on systems other than Sun Solaris, as it is just the GUI-world's name for any text-based interface. Console being the physical intefaces that computer operators used in the days before microcomputers (ie, a keyboard and 'green screen').

-------------------------------------------------------------------

I always think of console mode as being when you plug a console cable into the console port on the back on the machine to get the lowest-level cmdline access to it (if it simply *won't* boot for example.

I seem to remember using the word "console" when using WinNT too... you see, in my eyes, a console is different to a command line...

I see your point though

-------------------------------------------------------------------

You're right about it, but how can I simulate non-character keys like ENTER, ESC, TAB, CTRL, etc?

-------------------------------------------------------------------

These are all escape characters...... try putting a backslash (\) in front of their ASCII code... that might work... I'll try to find out more when I get back into work.

-------------------------------------------------------------------

Actually, that might not always work. You're thinking too much into C strings.

What will definitely work, tho, is to populate the text file with 'dummy' characters to represent the non-printables, then editing the file in a hex editor and replacing the 'dummy' values with the relevant ones.

Some of the non-character keys (eg. ENTER, TAB) are printable and so do not need dummy-replacements.

Other keys, such as CTRL, SHIFT & ALT have no ASCII values as they are modifiers, however, the particular OS that you are using should have a mapping for these onto it's own character set (which is an extension of the 96(32-127) ASCII characters).

-------------------------------------------------------------------

It's me again.

I finally decided to learn more about a program called "expect" that comes with the Red Hat CD-ROM and it does what I want. Moreover it's pretty easy to use.

Thanks a lot to all those people who tried to help me.

Have a Linux Problem
Linux Forum - Do you have a Linux Question?

Linux Books
Linux Certification, System Administration, Programming, Networking Books

Linux Home: Linux System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.