Use TELNET in Shell Script or Non-interactive Mode

Use TELNET in Shell Script or Non-interactive Mode

      TELNET  is used to connect to remote machines to send data or execute commands either using interactive or non-interactive. Interactive mode is quite common where two users connect each others machine to communicate information. However we can automate the TELNET connection using the following command. Note that the sleep command is essential to make the connect to remote computer machine successful.

(
echo “Content or Command”
sleep 2
) | telnet Remote_Machine_Hostname/IP Port_Number

How to test the script?

Machine1(Linux)

      Execute the command nc -l 30000 in the terminal which make the system to listen to the port 30000. You cannot use the ports from 0 to 1023 which are reserved ports. The allowed ports are from 1024 upto 65535.

Machine2(Linux)

      Execute the following command in the terminal.

(
echo “Content or Command”
sleep 2
) | telnet Machine1_Hostname/IP 30000 

      You can also execute the command as a shell script and the the port listener and the sender can be in the same system. On execute the above command, you can see the content/command statements in Machine1. Make sure to add sleep command.

[ YOU MAY ALSO LIKE ]

One thought on “Use TELNET in Shell Script or Non-interactive Mode

Leave a Reply