Telnet and Grep source file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Telnet and Grep source file
# 1  
Old 08-18-2011
Data Telnet and Grep source file

Hi,

I need a script to do the following:
1. Telnet into a remote power controller for the switch (done)

2. Find the power controller version. In order to do that my script should run grep and the keyword to search is "network" (need help)

3. Do a bunch of other stuff.

Now, once you telnet into the server, you're presented with a command line interface which allow only numeric entries to select various choices.

Eg. a> telent x.x.x.x

Press 1) for Device Manager
2) for Outlet Management
3) for Logout
and so on...

Can I have my script run grep in such a situation?


Thanks!
# 2  
Old 08-18-2011
Your best bet here is to use an expect script. Perhaps something like this would be a good starting point:

Code:
#!/usr/bin/expect
spawn telnet x.x.x.x
expect {
    "User: " { send "punnett\r" ; continue }
    "Password: " { send "secret\r" }
    timeout { puts "Connection failed" ; exit }
}
send "1\r"
send "2\r"
send "3\r"
expect eof

# 3  
Old 08-18-2011
Thanks for the reply. As I see it, your code will telnet into server, enter password(exit in case its wrong) and make choices in the menu. I have that part done.
My problem however, is that after successful telnet into the system, I need my script to run grep and look for lines having the keyword "network" and then do things based on that.

Any suggestions??
# 4  
Old 08-18-2011
Yes, just use expect and do what you want eg:

Code:
#!/usr/bin/expect
spawn telnet x.x.x.x
expect {
    "User: " { send "punnett\r" ; continue }
    "Password: " { send "secret\r" }
    timeout { puts "Connection failed" ; exit }
}
# Send command to display network type
send "1\r4\r"
 
expect {
    "network A" {puts "Network type is A" ; send "some network A stuff" }
    "network B" {puts "Network type is A" ; send "some network B stuff here" }
    timeout { puts "No matching network string found - nothing to do" }
}
# Send command to logout
send "3\r"
expect eof

# 5  
Old 08-19-2011
Ah, but we're still missing the point. I need to do the

#Send command to display network type

This is the part I am stuck with. You see, once you telnet into the system, it displays a some information and then takes you to a Command Line Menu. You can only press 1 or 2 or 3 etc and make choices. I want the script to do a grep at that point.
Does that make my question clearer? How do I go about it?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Match the amount fields in the source file vs trigger file

Hello, I have to write a script to compare the sum of the amount fields in a source file and the amount field in another file. details are: based on the name of the source file (say SALES as an example), a file already available in a path will be grabbed (say SALES_ParmFile) and this file... (4 Replies)
Discussion started by: vijaylak
4 Replies

2. Shell Programming and Scripting

Split File by Pattern with File Names in Source File... Awk?

Hi all, I'm pretty new to Shell scripting and I need some help to split a source text file into multiple files. The source has a row with pattern where the file needs to be split, and the pattern row also contains the file name of the destination for that specific piece. Here is an example: ... (2 Replies)
Discussion started by: cul8er
2 Replies

3. Programming

how to copy downloaded file into my source file folder (putty/unix)

I need to "Ensure that when you download libchat.a from the VLE you have copied it to the same folder on ius as your source files. You then refer to the library (and the libraries it needs) with: gcc -o outputfile sourcefile.c -L. -lchat -lsocket -lnsl" But I have no idea what this means! (I... (2 Replies)
Discussion started by: fakuse
2 Replies

4. Shell Programming and Scripting

rsync - update file on backup when file renamed on source

hi all, Please help me with rsync. I configured rsync to preserve timestamps using the -a option. When i renamed fileA to fileB on source machine I have to copies at the backup server. The aim is to keep the most recent file. fileA & fileB has same contents. When i renamed fileB to... (2 Replies)
Discussion started by: coolatt
2 Replies

5. UNIX for Advanced & Expert Users

grep source code and exclude comments

I often find myself grepping source code for a variable name and many times the name would be present in comment lines that I 'd prefer not to see. Do you guys know any tricks to filter out comments? Example: snippet of the source code /*** * type comment 1 ***/ void ... (7 Replies)
Discussion started by: migurus
7 Replies

6. Shell Programming and Scripting

Webpage to Telnet via Perl and Expect: Telnet problem?

Somewhat long story: I have a simple Perl CGI script that uses Expect to Telnet to a device and grab some data, and then spits it back to Perl for display on the Webpage. This works for many devices I've tried, but one device just fails, it keeps rejecting the password on this device, only... (1 Reply)
Discussion started by: jondo
1 Replies

7. Shell Programming and Scripting

Post Shell programming: Question about source a file and read data from the file

This is shell programming assignment. It needs to create a file called .std_dbrc contains STD_DBROOT=${HOME}/class/2031/Assgn3/STD_DB (which includes all my simple database files) and I am gonna use this .std_dbrc in my script file (read the data from the database files) like this: .... (3 Replies)
Discussion started by: ccwq
3 Replies

8. UNIX for Dummies Questions & Answers

how to grep the source file

hi folks... lets suppose i do ps -ef | grep telnet <ip add> then... whats the way to find find out from which file this process i.e. telnet <ip add> is called. (2 Replies)
Discussion started by: icecool79us
2 Replies

9. UNIX for Advanced & Expert Users

how to grep the source file

hi folks... lets suppose i do ps -ef | grep telnet <ip add> then... whats the way to find find out from which file this process i.e. telnet <ip add> is called. (1 Reply)
Discussion started by: icecool79us
1 Replies
Login or Register to Ask a Question