heyblackduck
heyblackduck

Reputation: 117

Pipe Input on a timer

I have a program that asks for input but it takes a while to load up.

I need a bash script that will pipe out the output into a named pipe.

I need a command that will cause my echo to insert my input after the program prompts for input. This is my command right now but it pipes in the input before my prompt.

echo "R" | nc localhost 123 > fifo

This will result in the following output:

usernname@name:
R
Please enter in an input (R, Q, T):

So my command needs to "wait" until my program prompts then pipe in the input. Any ideas? This needs to be in a bash script

Upvotes: 0

Views: 138

Answers (1)

John Zwinck
John Zwinck

Reputation: 249133

You can use sleep:

(sleep 3; echo "R") | nc localhost 123 > fifo

Obviously this has a race condition, and so for industrial applications you should use expect instead.

Upvotes: 1

Related Questions