Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to pass ^] character for a script to automate sending commands in my telnet device ? Post 303046039 by v4vivekss on Wednesday 22nd of April 2020 08:41:44 AM
Old 04-22-2020
How to pass ^] character for a script to automate sending commands in my telnet device ?

Hi,

I usually log into my device using
Code:
telnet IP PORT

like this

Code:
[xadmin@x-123-b3 ~]$ telnet 172.5.23.6 50006
Trying 172.5.23.6..
Connected to 172.5.23.6.
Escape character is '^]'.
$$

Here i press ctrl+] and a 'telnet>' prompt comes up.
Then I send 'send brk' command thus a '?' prompt show up. Here I give the 'login' command and I get "Enter your username " prompt .
Then I use the credentials to log in to the device.

I want to automate the process using a shell script (I dont have permission to install expect on the device )and send a command after logging into the device. I am having trouble sending the ctrl+] using the shell script. Here is my script as of now.

Code:
HOST='172.5.23.6 50006'
USER='username'
PASSWD='passwrd'


(
echo open "$HOST"
sleep 2
echo "^]"
sleep 2
echo "send brk"
sleep 2
echo "login"
sleep 2
echo "$USER"
sleep 2
echo "$PASSWD"
sleep 2
echo "$CMD"
sleep 2
echo "exit"
) | telnet

when i run this i get
Code:
[xadmin@x-123-b3]$ sh telnet.sh
telnet> Trying 172.5.23.6...
Connected to 172.5.23.6.
Escape character is '^]'.
$$
Connection closed by foreign host.

I believe the ctrl+] is not going through the script. How can I change the script to perform the above said process? Thanks in advance.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

automate Telnet ?

Hi, I have to run a script shell on a unix server from my windows PC. For that, I open a cmd windows and use Telnet to connect to the unix and run the script (by the .profile of a special user). Is it possible to automate Telnet in order to not enter the user and the password ? Anyway, has... (4 Replies)
Discussion started by: tbeghain
4 Replies

2. UNIX for Advanced & Expert Users

Automate Script using pkgrm/pkgadd commands

This is my first post so hello to all of you! I have a script in bash-3.00 that needs to execute the following: pkgrm (to remove an existing package) pkgadd -d ( to install a new package) The problem is that both commands prompt me to answer either y,n or q in order to proceed with... (13 Replies)
Discussion started by: Insight
13 Replies

3. Shell Programming and Scripting

Expect script to automate telnet session

Hi all, I am currently running a daemon which creates a virtual terminal for testing purposes. Essentially, if I were to interact with it manually, this is what I get. john@test1:~$telnet localhost 7777 Trying ::1... Connected to localhost. Escape character is '^]' mip6d> pl eth2... (6 Replies)
Discussion started by: abxccd
6 Replies

4. Shell Programming and Scripting

Need Help with commands to automate.

HI, In some test cases, I used tools like "dd" and "shed" to manually read a block from the disk, modify it using a hex editor and write it back using "dd". I need help with some linux commands I can use to read the block and change the data to induce the corruption....as I want to automate my... (3 Replies)
Discussion started by: prinsh
3 Replies

5. Shell Programming and Scripting

Script which telnets to a device, runs commands and prints output to a file

I am connecting to a device using telnet, I want my script to perform certain commands : ie- show device , show inventory..etc and write the output it sees from the terminal to a file. this is what I have got : #!/usr/bin/expect -- set running 1 spawn telnet <ip address> expect ... (1 Reply)
Discussion started by: samantha123
1 Replies

6. Shell Programming and Scripting

How to pass enter key or selected character in bash script?

hi, i've bash script thats working... but now i need to add a line....that prompts for user input....like yes and 1 as complete install.... so here's how it looks... $ cd 9200 (cd into directory) $./install (hv to type ./install to run install then ask for) ----do you want to... (4 Replies)
Discussion started by: kernel11
4 Replies

7. Shell Programming and Scripting

Unable to automate telnet login

i have to connect windows server from one of the unix box so i am using telnet and below is my following code #!/bin/sh host=hostname log=loginid port=23 pass=password cmd1=mkdir test1234 ( echo open ${host} ${port} sleep 1 echo ${log} sleep 3 echo "\r\n" sleep 3 echo ${pass}... (11 Replies)
Discussion started by: chandan.p
11 Replies

8. Open Source

Help with writing Shell Script to automate process using multiple commands

Hello! Need help to write a Linux script that can be run from windows using command/Cygwin/any other way. I am new to scripting, actually i am trying to automate server health check like free disk space, memory along with few services status, if any services is not running then start services ,... (7 Replies)
Discussion started by: Sayed Ibrahim
7 Replies

9. UNIX for Beginners Questions & Answers

How can i create a script that will ssh a device and type some commands?

Hi Guys, this is the scenario: ubuntu pc and I have 10 wireless devices that I need to check their firmware version. I would like to create a script that it will ask me IP, after I enter it, I hit enter then it will show me the version of the firmware. this is what i do. ssh... (9 Replies)
Discussion started by: gabak
9 Replies

10. UNIX for Beginners Questions & Answers

Script require to do telnet & run few commands

I am new in scripting, I need script(BASH) which do telenet to one of the elements & run few commands , after running it successfully it will check status of files & exit. Help is greatly appreciated 🙏 (2 Replies)
Discussion started by: Vinesh_123
2 Replies
TELNET(1C)																TELNET(1C)

NAME
telnet - user interface to the TELNET protocol SYNOPSIS
telnet [ host [ port ] ] DESCRIPTION
Telnet is used to communicate with another host using the TELNET protocol. If telnet is invoked without arguments, it enters command mode, indicated by its prompt ("telnet>"). In this mode, it accepts and executes the commands listed below. If it is invoked with arguments, it performs an open command (see below) with those arguments. Once a connection has been opened, telnet enters an input mode. The input mode entered will be either "character at a time" or "line by line" depending on what the remote system supports. In "character at a time" mode, most text typed is immediately sent to the remote host for processing. In "line by line" mode, all text is echoed locally, and (normally) only completed lines are sent to the remote host. The "local echo char- acter" (initially "^E") may be used to turn off and on the local echo (this would mostly be used to enter passwords without the password being echoed). In either mode, if the localchars toggle is TRUE (the default in line mode; see below), the user's quit, intr, and flush characters are trapped locally, and sent as TELNET protocol sequences to the remote side. There are options (see toggle autoflush and toggle autosynch below) which cause this action to flush subsequent output to the terminal (until the remote host acknowledges the TELNET sequence) and flush previous terminal input (in the case of quit and intr). While connected to a remote host, telnet command mode may be entered by typing the telnet "escape character" (initially "^]"). When in command mode, the normal terminal editing conventions are available. COMMANDS The following commands are available. Only enough of each command to uniquely identify it need be typed (this is also true for arguments to the mode, set, toggle, and display commands). open host [ port ] Open a connection to the named host. If no port number is specified, telnet will attempt to contact a TELNET server at the default port. The host specification may be either a host name (see hosts(5)) or an Internet address specified in the "dot notation" (see inet(3N)). close Close a TELNET session and return to command mode. quit Close any open TELNET session and exit telnet. An end of file (in command mode) will also close a session and exit. z Suspend telnet. This command only works when the user is using the csh(1). mode type Type is either line (for "line by line" mode) or character (for "character at a time" mode). The remote host is asked for permis- sion to go into the requested mode. If the remote host is capable of entering that mode, the requested mode will be entered. status Show the current status of telnet. This includes the peer one is connected to, as well as the current mode. display [ argument... ] Displays all, or some, of the set and toggle values (see below). ? [ command ] Get help. With no arguments, telnet prints a help summary. If a command is specified, telnet will print the help information for just that command. send arguments Sends one or more special character sequences to the remote host. The following are the arguments which may be specified (more than one argument may be specified at a time): escape Sends the current telnet escape character (initially "^]"). synch Sends the TELNET SYNCH sequence. This sequence causes the remote system to discard all previously typed (but not yet read) input. This sequence is sent as TCP urgent data (and may not work if the remote system is a 4.2 BSD system -- if it doesn't work, a lower case "r" may be echoed on the terminal). brk Sends the TELNET BRK (Break) sequence, which may have significance to the remote system. ip Sends the TELNET IP (Interrupt Process) sequence, which should cause the remote system to abort the currently running process. ao Sends the TELNET AO (Abort Output) sequence, which should cause the remote system to flush all output from the remote system to the user's terminal. ayt Sends the TELNET AYT (Are You There) sequence, to which the remote system may or may not choose to respond. ec Sends the TELNET EC (Erase Character) sequence, which should cause the remote system to erase the last character entered. el Sends the TELNET EL (Erase Line) sequence, which should cause the remote system to erase the line currently being entered. ga Sends the TELNET GA (Go Ahead) sequence, which likely has no significance to the remote system. nop Sends the TELNET NOP (No OPeration) sequence. ? Prints out help information for the send command. set argument value Set any one of a number of telnet variables to a specific value. The special value "off" turns off the function associated with the variable. The values of variables may be interrogated with the display command. The variables which may be specified are: echo This is the value (initially "^E") which, when in "line by line" mode, toggles between doing local echoing of entered charac- ters (for normal processing), and suppressing echoing of entered characters (for entering, say, a password). escape This is the telnet escape character (initially "^[") which causes entry into telnet command mode (when connected to a remote system). interrupt If telnet is in localchars mode (see toggle localchars below) and the interrupt character is typed, a TELNET IP sequence (see send ip above) is sent to the remote host. The initial value for the interrupt character is taken to be the terminal's intr character. quit If telnet is in localchars mode (see toggle localchars below) and the quit character is typed, a TELNET BRK sequence (see send brk above) is sent to the remote host. The initial value for the quit character is taken to be the terminal's quit character. flushoutput If telnet is in localchars mode (see toggle localchars below) and the flushoutput character is typed, a TELNET AO sequence (see send ao above) is sent to the remote host. The initial value for the flush character is taken to be the terminal's flush character. erase If telnet is in localchars mode (see toggle localchars below), and if telnet is operating in "character at a time" mode, then when this character is typed, a TELNET EC sequence (see send ec above) is sent to the remote system. The initial value for the erase character is taken to be the terminal's erase character. kill If telnet is in localchars mode (see toggle localchars below), and if telnet is operating in "character at a time" mode, then when this character is typed, a TELNET EL sequence (see send el above) is sent to the remote system. The initial value for the kill character is taken to be the terminal's kill character. eof If telnet is operating in "line by line" mode, entering this character as the first character on a line will cause this char- acter to be sent to the remote system. The initial value of the eof character is taken to be the terminal's eof character. toggle arguments... Toggle (between TRUE and FALSE) various flags that control how telnet responds to events. More than one argument may be specified. The state of these flags may be interrogated with the display command. Valid arguments are: localchars If this is TRUE, then the flush, interrupt, quit, erase, and kill characters (see set above) are recognized locally, and transformed into (hopefully) appropriate TELNET control sequences (respectively ao, ip, brk, ec, and el; see send above). The initial value for this toggle is TRUE in "line by line" mode, and FALSE in "character at a time" mode. autoflush If autoflush and localchars are both TRUE, then when the ao, intr, or quit characters are recognized (and transformed into TELNET sequences; see set above for details), telnet refuses to display any data on the user's terminal until the remote sys- tem acknowledges (via a TELNET Timing Mark option) that it has processed those TELNET sequences. The initial value for this toggle is TRUE if the terminal user had not done an "stty noflsh", otherwise FALSE (see stty(1)). autosynch If autosynch and localchars are both TRUE, then when either the intr or quit characters is typed (see set above for descrip- tions of the intr and quit characters), the resulting TELNET sequence sent is followed by the TELNET SYNCH sequence. This procedure should cause the remote system to begin throwing away all previously typed input until both of the TELNET sequences have been read and acted upon. The initial value of this toggle is FALSE. crmod Toggle carriage return mode. When this mode is enabled, most carriage return characters received from the remote host will be mapped into a carriage return followed by a line feed. This mode does not affect those characters typed by the user, only those received from the remote host. This mode is not very useful unless the remote host only sends carriage return, but never line feed. The initial value for this toggle is FALSE. debug Toggles socket level debugging (useful only to the superuser). The initial value for this toggle is FALSE. options Toggles the display of some internal telnet protocol processing (having to do with TELNET options). The initial value for this toggle is FALSE. netdata Toggles the display of all network data (in hexadecimal format). The initial value for this toggle is FALSE. ? Displays the legal toggle commands. BUGS
There is no adequate way for dealing with flow control. On some remote systems, echo has to be turned off manually when in "line by line" mode. There is enough settable state to justify a .telnetrc file. No capability for a .telnetrc file is provided. In "line by line" mode, the terminal's eof character is only recognized (and sent to the remote system) when it is the first character on a line. 4.2 Berkeley Distribution May 10, 1986 TELNET(1C)
All times are GMT -4. The time now is 08:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy