I made this executable because I used to play on a MUD, which was essentially a server to which you connect to through telnet to play in a multiplayer world. What annoyed me was how difficult it was to remember the automatically generated password that comes with your account and how repetitive the routine commands were.
Hence why I made a shell script that starts off as any other automatic telnet (or ssh, if you choose so) networking tool, sending pre-written commands to a server with set delays in between of each command and live feedback from the server, but after sending these pre-written commands, it starts listening to the user's input and acts as if it were a regular telnet connection from there on. Here is the script:
echo "Now connecting..."
FIFO_IN=$(mktemp -u)
FIFO_OUT=$(mktemp -u)
mkfifo "$FIFO_IN"
mkfifo "$FIFO_OUT"
trap 'rm -f "$FIFO_IN" "$FIFO_OUT"' EXIT
# Connect telnet to the pipes
stdbuf -oL -i0 'telnet' 'SERVER_ADDRESS' 'PORT_NUMBER' < "$FIFO_IN" > "$FIFO_OUT" &
TELNET_PID=$!
echo "Connect..."
# Wait for telnet to be established
sleep 3
exec 3> "$FIFO_IN"
cat "$FIFO_OUT" &
CAT_PID=$!
echo "Logging in..."
printf '%s\n' "connect Chip01 Password" >&3
sleep 1
printf '%s\n' "inventory" >&3
sleep 2
printf '%s\n' "go north east north north west" >&3
sleep 3
# More pre-written commands may follow...
echo "Done sending pre-written commands."
echo "Now switching from pre-written commands to terminal input..."
# Closing first session before opening the new one for the terminal input
exec #>&-
# Connect terminal input to telnet input
tee "$FIFO_IN" > /dev/null
# When tee exits (Ctrl+C), kill the other processes
kill $TELNET_PID
kill $CAT_PID
So it worked pretty well, but I noticed over time that the more commands I entered a while after the automatic ones were sent, the more I experience lag. I tried a regular connection using the telnet command, and it never happened. Then once more I tried with the executable, and it gradually started lagging for each command I enter.
Its nothing bad, and as long as you enter under 100 commands you dont experience any visible differences, but I have a hunch that it might be buffering the commands I enter somewhere, and in a bad way, slowing down the performance.
If you have any idea for why it does so, or any ideas on things I should try, please tell me :)
expect\$\endgroup\$