I'm trying to code a script where I can connect via telnet to another server and execute certain operations, but I'm having problems with the result of this process.
The objective is to connect to a server, execute one command, and save the result into a .txt file. It is desirable that the parameters or input are in an input file .txt, which is read by the script and executed. (I have not done that part yet.)
Here's what I have so far.
#!/bin/bash
{
sleep 5
echo "user"
sleep 3
echo "password"
sleep 3
echo "clear"
echo "COMMANDS" >> /ROUTE/output_file.txt
echo exit
} | telnet 172.22.89.133
In this case I'm getting the output file filled with the command, but obviously I need the result of that command. I know it is a little silly, but I've been trying in many ways and I am still getting the same result.
How can I get this done?
Expect
to control an interactive program liketelnet
. – Barmar Apr 7 '16 at 19:46