Search code examples
shspecial-characterstelnet

How do I send an SOH character over telnet from an sh script?


I'm running a fairly simple sh script that automates a few telnet commands, but I've run into an issue.

One command requires an SOH character (normally sent using CTRL + A) followed by the command name, then enter. This is a snippet of that, but it doesn't work:

#!/bin/sh
(
echo open 12.34.56.78
sleep 2
echo -e "\u001""commandname"
echo -e "\n"
sleep 3
echo "quit"
) | telnet

What am I doing wrong? How can I send that SOH character via the script?


Solution

  • Use printf.

    {
      printf "open 12.34.56.78\n"
      sleep 2
      printf '\001commandname\n\n'
      sleep 3
      printf 'quit\n'
    } | telnet