1

is there any way I can pass commands to the CLI of a tool directly?

I would like to script some actions, for example:

./OpenBTS < "tmsis"

I do not need to retrieve the results (I watch it in the log file). Do you have any idea how I could realize that? There is now way to do this using command line parameters, at least not that I found out. So it looks like I have to figure out sth myself. Any idea? Maybe I could automate screen in a way to detect the prompt and "paste" my command there. Are there tools for this on Linux?

3 Answers 3

5

Sounds like you are looking for expect

1
  • wow! Exactly! Big thanks. very nice tool, good to knwow it now =)
    – Steve
    Jul 31, 2011 at 9:37
1

You can try it with a heredoc, something like:

./OpenBTS <<EOF
tmsis
EOF

as in the following transcript, which feeds input into sed:

pax$ sed 's/^/Q/' <<EOF
> hello
> goodbye
> EOF
Qhello
Qgoodbye

Alternatively, you can just echo stuff directly into it, like

echo "tmsis" | ./OpenBTS

as per the following example:

pax$ echo 'hello
goodbye' | sed 's/^/Q/'
Qhello
Qgoodbye
0

There is no specific way to do this, but if the tool listens on stdin then you can use a heredoc for this.

./sometool << EOF
action1
action2
quit
EOF
1
  • Thanks for the idea. It is not working in this case but that's not related to the command. Will use it for sure later. Thx for telling me that trick :)
    – Steve
    Jul 31, 2011 at 9:37

You must log in to answer this question.