LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-09-2011, 12:18 PM   #1
Speeddymon
LQ Newbie
 
Registered: Jun 2011
Posts: 4

Rep: Reputation: Disabled
[solved] Expect question


I'm working on an expect script to automate remote logins and in turn, run certain commands rather than just dropping to an interactive shell.

I am new to TCL and expect, but I've found a lot of helpful stuff in the man page and online. One thing I tried googling for but didn't come up with any results on, is how to use non-expect, TCL code (if statements, etc) nested inside of an expect statement.

Something like the following code fragment is what I would like to get working, if at all possible, without having to write multiple expect statements:

Code:
# interact will be the last arg, if it exists, and should be either 1 or 0 for this fragment
set interactive [lrange $argv end end]

expect {

  # expect the end of the colorized prompt (because our system
  # designers are stupid and want pretty colors)
  "\[\033\[01;36m\]\$ \[\033\[00m$" {
    if {$interactive} {
      interact      
    } else {
      send -- "sudo bash\r"
      exp_continue
    }
  }
}
I essentially just want to be able to have if statements used within the context of certain output from the shell that I am logging into. Any ideas?

EDIT:

After trying the above code fragment (which I didn't try quite like this), I was able to get it to work.

Last edited by Speeddymon; 08-09-2011 at 12:27 PM. Reason: answered my own question
 
Old 08-11-2011, 12:21 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hello,

Glad you got is solved. Off the Zero Reply List.

Kind regards,

Eric
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
expect (Tcl) question kristof_v Programming 2 01-24-2013 05:32 AM
A question about using expect and send thomas2004ch Linux - Software 5 03-29-2011 08:27 AM
A question about expect. imjoe Programming 1 10-26-2005 04:42 AM
expect question deiussum Programming 0 08-05-2005 03:51 PM
expect question reitzell Programming 1 11-20-2004 09:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration