cat & telnet


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cat & telnet
# 1  
Old 05-11-2010
cat & telnet

cat & telnet
hello,

I need some help on using a file with the cat command. I want to set up a telnet connection with a network device with the ip-adress 10.3.0.1. Just executing the command 'telnet 10.3.0.1' gives a menu. For example, to show the help of the menu, you need to type '?'.

Now I want to go through the menu with commands (like '?') that are in a file. For this I want to use the command:
cat filename | telnet 10.3.0.1

When I try this, the telnet connection is established, but then it closes immediately afterwards. So I suppose something's wrong with the file. But I have no idea what the file should look like. For example, do you need to mention the enters after a command in a certain way?

just to be clear: the command in the menu that I want to execute are:
"?" -> enter
"projector" -> enter
"exit" -> enter


thanks in advance,

Michaël
# 2  
Old 05-11-2010
It may be inputting the data and finding EOF before it even gets to the menu. The expect tool is often used to automate interactive prompts like this, since it can be told to wait for responses or prompts before sending data.

Also see useless use of cat.
# 3  
Old 05-11-2010
To make a shell script which can telnet automatically and run commands on the other machine and end the telnet session without any interaction from the user, you need to install EXPECT and TCL packages on your unix system.

If you are done with above mentioned then, you can write a script similar to following (as per your requirements) :

Code:
#!/usr/local/bin/expect -f ####/usr/local/bin/expect is the directory where expect was installed 
log_user 0 ####this command is used to hide the conversationn between the script and the other machine 
set address [lindex $argv 0] ###assign the first passed parameter while calling the script to $address 
set username [lindex $argv 1] ###assign the 2nd passed parameter while calling the script to $username 
set password [lindex $argv 2] ###assign the 3rd passed parameter while calling the script to $password 
spawn telnet ${address} ###start the telnet session to machine with IP=$address 
###start conversation with the machine: 
expect "login:" 
send -- "${username}\r" 
expect "Password:" 
send -- "${password}\r" 
expect "$ " 
send -- "#!/bin/ksh\r" ###declare the shell to be used (optional) 
expect "$ " 
send -- "###type here any command you want to execute" 
expect "$ " 
send -- "exit\r" ###end the telnet session and exit the script


to execute this script, you can type:

Code:
$ expect_script "address" "username" "password" ###the script name is "expect_script"

but before u call the expect script, you should make the expect script executable, and this can be done by typing:
Code:
$ chmod +x expect_script

You can also call the above script from any other script....SmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem while displaying(cat) file content inside telnet loop .

Hi Team, Not getting the file output inside my email which i am sending from unix box. . Please refer the below code : #!/bin/sh { sleep 5 echo ehlo 10.56.185.13 sleep 3 echo mail from: oraairtel@CNDBMUREAPZP02.localdomain sleep 3 echo rcpt to: saurabhtripathi@anniksystems.com... (1 Reply)
Discussion started by: tripathi1990
1 Replies

2. UNIX for Dummies Questions & Answers

Cat Input & Output to a Log file

Team, we use below command to store the contents in a logfile. cat a.txt > a.log a.txt content is 123 345 Is there any options available to store the command used also? for eg a.log may show as cat a.txt 123 345 (5 Replies)
Discussion started by: sid2013
5 Replies

3. Shell Programming and Scripting

for i in `cat myname.txt` && for y in `cat yourname.txt`

cat myname.txt John Doe I John Doe II John Doe III ----------------------------------------------------------------------- for i in `cat myname.txt` do echo This is my name: $i >> thi.is.my.name.txt done ----------------------------------------------------------------------- cat... (1 Reply)
Discussion started by: danimad
1 Replies

4. Shell Programming and Scripting

cat & awk

Hi there, Can show some hit why i got this error? For eg i have a.txt in which consist of contents as below 1|781494-0015|IV\|I||C|RECHARGE|Success\|V\|\||2007-12-04 02:33:13.000| 2|762405-0405|IV\|I||C|RECHARGE|Success\|V\|\||2007-12-04 02:33:17.000| In fact , i want to perfrom to have... (2 Replies)
Discussion started by: rauphelhunter
2 Replies

5. UNIX for Advanced & Expert Users

diable telnet & ftp

Hi All, I need to stop all the services for telnet & FTP as we want our server to be more secure. Please give me some steps for jumping to SSH protocol. How can i disable telnet & ftp service on my server. (1 Reply)
Discussion started by: pradeep_desh
1 Replies

6. Shell Programming and Scripting

telnet & su in shell script

Hi, Any scripting experts out there that can point me to the right direction of writing a script using telnet and su to access a server without any users interaction such as login and entering passwd. Thanks. Thanks in advance vastare (1 Reply)
Discussion started by: vastare
1 Replies

7. Cybersecurity

telnet on AT&T MLS V

How do I enable telnet access to a system running AT&T MLS? (1 Reply)
Discussion started by: smartgod
1 Replies

8. UNIX for Advanced & Expert Users

SCO OpenServer & telnet

I was wondering if anyone knew how I would open up my server so it can be telneted into from other subnets.:confused: (2 Replies)
Discussion started by: cparks73
2 Replies

9. UNIX for Dummies Questions & Answers

rlogin & telnet

hi what is the main difference between rlogin and telnet? Or they are synonymous cheers (13 Replies)
Discussion started by: g-e-n-o
13 Replies
Login or Register to Ask a Question