?
Solved

Problem with an expect script using netcat under GNU/Linux

Posted on 2007-07-28
6
Medium Priority
?
1,973 Views
Last Modified: 2013-11-22
I am using expect under GNU/Linux. I am also using netcat (nc).
My problem is that when I run the following expect script it does not work. It never matches one of the choices in the expect list. I suspect that I cannot do what I want and hence the question to an expert. The problem may be with the fact that spawn is not able to synchronize with the command line I have issued. So far I have enabled debug and have seen that there is a problem with the parent being synchronized with the child.

Does anyone know of a way to do the equivalent and have it work with expect?

spawn echo "CMDTYPE" | nc dhcp66 17777
expect {
   "VIDEO"  { puts "video product" }
   "DATA"   { puts "data product" }
}

# this does work (example only)
spawn echo "VIDEO"
expect {
   "VIDEO"  { puts "video product" }
   "DATA"   { puts "data product" }
}
0
Comment
Question by:Anthony2000
  • 2
  • 2
4 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 19593249
sounds like you're trying to connect to an ftp service
if that is the purpose you better use an ftp client instead of netcat
Also some ftp clients can be scripted by its own, without using expect.
0
 
LVL 8

Author Comment

by:Anthony2000
ID: 19594012
Its an application that accepts commands much like a command line interface.  I am planning to write my own simple version of netcat that sends a command and waits for a reply. I was hoping that I may have missed some other easy way (a simple tweak of my expect script).
0
 
LVL 8

Accepted Solution

by:
Anthony2000 earned 0 total points
ID: 19691617
To fix ths problem, I created a special version of netcat that accepts as a commandline parameter the string to be sent. I used -T <text to send>
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 19753017
agreed
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question