Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to create a simple script that initiates a simple gui-based program (think ncurses-style, text-based graphics in a shell) in Debian. I only access the server through SSH, so I can't do standard macros or anything.

The input is always the same: I just need it to start the program, then within the context of the program, send an "enter" keystroke, an "R" keystroke, and an "F7" keystroke.

I've been working on this for a while now, and I can't seem to figure anything out. Is there any way to do this within a bash script?

Thank you and have a good day

share|improve this question
1  
expect could work for that. –  Bobby Jul 22 '12 at 11:58
add comment

migrated from stackoverflow.com Jul 21 '12 at 22:55

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 0 down vote accepted

This seems very similar to a recent question.

http://stackoverflow.com/questions/11596059/how-do-i-read-any-one-key-in-bash/11596145#11596145

read -n 1 x; while read -n 1 -t .1 y; do x="$x$y"; done

But as mentioned in that thread, using dialog or similar scripting menuing programs would be the better option.

Or...are you wanting to send those keystrokes to a program? If so, you probably want to use expect.

share|improve this answer
    
I am trying to send the input TO a program. I.E. I want to automatically run the binary, which opens the text gui. I then want the program to automatically start based on the static keypresses that occur within the context of the program. –  user115360 Jul 22 '12 at 4:51
    
@user115360: So then expect is what you want. –  Seth Robertson Jul 22 '12 at 12:19
add comment

This would do:

[root@w4n-dl-c60-64-yannick ~]# cat test.sh
#!/bin/bash
echo "The year is: $var_year"
read var_year

echo -n "Enter your name and press [ENTER]: "
read var_name
echo "Your name is: $var_name"

echo "You are $((2012 - $var_year)) years old!"
echo "You can go on!...."
read var_con
[root@w4n-dl-c60-64-yannick ~]# ./test.sh
The year is:
1980
Enter your name and press [ENTER]: Yannick
Your name is: Yannick
You are 32 years old!
You can go on!....

[root@w4n-dl-c60-64-yannick ~]#
share|improve this answer
    
This doesn't seem to work with binaries. I need to script static input to occur at set points according to a binary's prompts. –  user115360 Jul 20 '12 at 20:11
    
Anyone else have a suggestion? –  user115360 Jul 21 '12 at 5:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.