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 03-07-2011, 12:05 PM   #1
Stuart07
LQ Newbie
 
Registered: May 2006
Location: Manchester, NH
Distribution: CentOS5.5
Posts: 13

Rep: Reputation: 0
Is it possible to control VI with tcl and expect ?


I'm using expect to log into a remote server and run a script. I want to able to have expect edit the output from that script, on the remote server, in VI.

Has anyone ever done this before, it seems as though the expect interpreter has nothing to expect once VI is started, the file pointer starts at the beginning of the line, and expect usually reads the characters before the pointer.

spawn ssh user1\@$remote_server

expect "password: "

send "$password\r"

expect "$ "

send "cd /data/home/user1/bin \r"

expect "$ "

send "/data/bin/script1.pl > report1.txt\r"

expect "$ "

send "vi /data/bin/report1.txt\r"

###This is where I get lost on what to have it expect
###Can you expect nothing ("") ?
###Can you have multiple "send" commands without expect
####in between?

expect ""

send {:g/search string/s/1.*0//}

expect ""

send "\r"

expect ""

send {:v/./d}




Any thoughts at all are appreciated!
Thanks,
Mark
 
Old 03-07-2011, 01:34 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 326Reputation: 326Reputation: 326Reputation: 326
Use sed instead of vi. It's intended for command line editing.
 
Old 03-08-2011, 08:30 AM   #3
Stuart07
LQ Newbie
 
Registered: May 2006
Location: Manchester, NH
Distribution: CentOS5.5
Posts: 13

Original Poster
Rep: Reputation: 0
Thanks.

After further testing, figured out you can have multiple send commands without an expect between. To accommodate the delay I used the sleep command. Seems to work although sed might be a more appropriate solution.

Code:
 send    ":"

        sleep 1

        send    "v/./d\r"

        sleep 1

        send    ":"

        sleep 1

        send    { %s/[a-z].*4//g }

        send    "\r"

        sleep 1

        send    ":"

        sleep 1

        send    { %s/\s\+$// }

        send    "\r"

        sleep 1

        send    ":"

        sleep 1

        send    "wq!"
 
  


Reply

Tags
expect, tcl, vi, vim


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
[SOLVED] Expect/TCL - can't find where I'm going wrong. Vryali Programming 2 01-24-2013 06:33 AM
expect (Tcl) question kristof_v Programming 2 01-24-2013 05:32 AM
fork: not enough memory in tcl/expect bharatbsharma Programming 4 04-11-2010 09:25 AM
TCL e EXPECT gustavolinux Programming 1 10-17-2008 09:03 AM
TCL, Expect, for Rsync - Please Help dholingw Programming 2 02-08-2004 10:27 AM


All times are GMT -5. The time now is 10:30 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration