LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-02-2013, 01:29 PM   #1
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,237

Rep: Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653
Cool Trying to use EXPECT heredoc to answer a ruby rake request...


Im not an expert at ruby, so my terminology might be a bit off. Apologies for that ahead of time.

I am trying to make an automated installation script for gitlab. This is the normal command, for the part that I am at, which will initialize the database:

Code:
cd /home/git/gitlab;
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
and this is the output:

Code:
This will create the necessary database tables and seed the database.
You will lose any previous data stored in the database.
Do you want to continue (yes/no)?
I type 'yes' here, and the database gets initialized correctly.

So im trying to EXPECT the (yes/no) bit and auto-answer 'yes' with this code/heredoc:

Code:
/usr/bin/expect -d << EOF
spawn sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
expect "Do you want to continue (yes/no)? "
send "yes\n"
EOF
which yields this, which isn't working:

Code:
expect version 5.45
argv[0] = /usr/bin/expect  argv[1] = -d  
set argc 0
set argv0 "/usr/bin/expect"
set argv ""
executing commands from command file
spawn sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {8790}

expect: does "" (spawn_id exp6) match glob pattern "Do you want to continue (yes/no)? "? no
This will create the necessary database tables and seed the database.
expect: does "This will create the necessary database tables and seed the database." (spawn_id exp6) match glob pattern "Do you want to continue (yes/no)? "? no


expect: does "This will create the necessary database tables and seed the database.\r\n" (spawn_id exp6) match glob pattern "Do you want to continue (yes/no)? "? no
You will lose any previous data stored in the database.
expect: does "This will create the necessary database tables and seed the database.\r\nYou will lose any previous data stored in the database." (spawn_id exp6) match glob pattern "Do you want to continue (yes/no)? "? no


expect: does "This will create the necessary database tables and seed the database.\r\nYou will lose any previous data stored in the database.\r\n" (spawn_id exp6) match glob pattern "Do you want to continue (yes/no)? "? no
Do you want to continue (yes/no)? 
expect: does "This will create the necessary database tables and seed the database.\r\nYou will lose any previous data stored in the database.\r\n\u001b[34mDo you want to continue (yes/no)? \u001b[0m" (spawn_id exp6) match glob pattern "Do you want to continue (yes/no)? "? yes
expect: set expect_out(0,string) "Do you want to continue (yes/no)? "
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "This will create the necessary database tables and seed the database.\r\nYou will lose any previous data stored in the database.\r\n\u001b[34mDo you want to continue (yes/no)? "
send: sending "yes\n" to { exp6 }
Can you help me get my EXPECTed (haha) result of answering 'yes' to this rake program so that it will initialize the database? I'd like to keep the simple heredoc, so that I may keep this all in one script. If that isn't possible, and I need an actual EXPECT program, that is completely fine as well.

Last edited by szboardstretcher; 09-02-2013 at 01:34 PM.
 
Old 09-02-2013, 02:12 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,237

Original Poster
Rep: Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653
Found a way around this using empty-expect:

Code:
empty -f -i in -o out sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
empty -w -i out -o in "(yes/no)? " "yes\n"
 
  


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
[root@fugo trace]# sh expect.sh expect.sh: line 9: expect: command not found sivaloga Linux - Kernel 1 08-22-2013 05:29 AM
Ruby/Rake install error on SiriProxy fmillion Linux - Software 1 01-23-2012 10:52 PM
VPS does not answer any DNS request peace18 Linux - Newbie 3 02-09-2011 01:08 AM
LXer: Basics 101: ruby python bash perl expect php, How do the exact same thing in th LXer Syndicated Linux News 0 10-05-2008 07:00 AM
A request: please don't reply to topics if you don't know the answer vharishankar General 17 04-10-2006 10:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:03 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration