Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Expect and Tcl


1 reply to this topic

#1 mizako

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 372 posts
  • Location:Spain
  • Interests:Computers, Usability, Internet, Web development, programming languages, soccer

Posted 18 August 2004 - 09:00 AM

Hi,
I am quite new in trap17 and i do not know if i am supposed to open new topics. If not please let me know.

I am using normally Perl at work but now i need to use expect. Expect is a language that allows you to interact with prompts such telnet, ftp and staff like that. I have to interact with some consoles simultaneosly and send both of them commands.

Expect uses tcl. I am really new with tcl. I need to open a file and read line by line in order to send those line to a console. Maybe anyone can help me with this basic operation. I think i have to use the exp_open command. In Perl would be something like this:
[br]
[/br]open <INPUT>, FileName[br]    or die "Can't open FileName for reading;[/br]while ( <INPUT> )[br]{[/br]print "$_"; #Operation with the line. I should make more complicated things;-)[br]}[/br]


#2 mizako

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 372 posts
  • Location:Spain
  • Interests:Computers, Usability, Internet, Web development, programming languages, soccer

Posted 20 August 2004 - 03:41 PM

Hi,
I create a simple Expect script to automate my ftp login into my trap account. I made my ftp uploads running the ftp command in linux so i created this script to save me time in typing my Login and password. It logins for you and returns you the control.
I hope it is useful for you guys. Remember just install expect and enjoy it:

[br][/br]set host your_name.trap17.com[br]set Login your_name[/br]set Passwd your_password[br][/br]spawn ftp $host[br]expect "Name (*):"[/br]send "$Login\r"[br]expect "Password:"[/br]send "$Passwd\r"[br]expect {[/br]    "ftp>" { interact }[br]    "Login failed." { exit 1 }[/br]    timeout { exit }
    }[br][/br]





Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users