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
SLEEP(1)						    BSD General Commands Manual 						  SLEEP(1)

NAME
sleep -- suspend execution for an interval of time SYNOPSIS
sleep seconds DESCRIPTION
The sleep command suspends execution for a minimum of seconds. If the sleep command receives a signal, it takes the standard action. When the SIGINFO signal is received, the estimate of the amount of seconds left to sleep is printed on the standard output. IMPLEMENTATION NOTES
The SIGALRM signal is not handled specially by this implementation. The sleep command allows and honors a non-integer number of seconds to sleep in any form acceptable by strtod(3). This is a non-portable extension, and its use will nearly guarantee that a shell script will not execute properly on another system. EXIT STATUS
The sleep utility exits 0 on success, and >0 if an error occurs. EXAMPLES
To schedule the execution of a command for x number seconds later (with csh(1)): (sleep 1800; sh command_file >& errors)& This incantation would wait a half hour before running the script command_file. (See the at(1) utility.) To reiteratively run a command (with the csh(1)): while (1) if (! -r zzz.rawdata) then sleep 300 else foreach i (`ls *.rawdata`) sleep 70 awk -f collapse_data $i >> results end break endif end The scenario for a script such as this might be: a program currently running is taking longer than expected to process a series of files, and it would be nice to have another program start processing the files created by the first program as soon as it is finished (when zzz.rawdata is created). The script checks every five minutes for the file zzz.rawdata, when the file is found, then another portion processing is done courteously by sleeping for 70 seconds in between each awk job. SEE ALSO
nanosleep(2), sleep(3) STANDARDS
The sleep command is expected to be IEEE Std 1003.2 (``POSIX.2'') compatible. HISTORY
A sleep command appeared in Version 4 AT&T UNIX. BSD
April 18, 1994 BSD
All times are GMT -4. The time now is 02:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy