Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-05-2011, 06:16 AM   #1
LQ Newbie
Registered: Jun 2011
Posts: 2

Rep: Reputation: Disabled
Question Run script from another with multiple user inputs and expect !

Hi all - newbie here and my first post - yay!

I am literally bashing (pun intended) my head against the keyboard at this minute!

I am trying to automate a script via cron for my centos server. The script requires two user inputs (e.g. read VAR). However, I do not want to edit the original file, as I would like to be able to run it normally as well. It is also made by someone else, and so if an update becomes available, it will be easier to install.

So... My idea is that i create a cron script, to run this second script from, and the only way i could find was with expect.

However I am having troubles, In order to test out expect, I have created the following:
echo "Begin"
echo "==============="
/usr/bin/expect - << EOD
# Comments on this script (name, what it does,
# optional)
spawn /bin/bash
expect ":"
send "./\r"
expect "name"
send "Me\r"
expect "like"
send "Pizza\r"
echo "==============="
echo "Fin"
echo "Name & Favourites Routine ..."
echo "What is your name?"
echo "Your answer: $ANSWER"
echo "What do you like?"
read LIKE
echo "You love to: $LIKE"
But when i run "./" from the command line, I receive the following:
spawn /bin/bash
User@MacBook ~: ./
Name & Favourites Routine ...
What is your name?
Your answer: Me
What do you like?
It looks as if the second input is completely ignored ?!!

Can anyone help with what i am doing wrong? or if there is a more elegant solution to running a script from a script with user inputs?

Old 06-05-2011, 11:09 AM   #2
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 97
It looks like you're on the right track, but that something is
ending prematurely.

Before the "close" try adding 'expect "You"' and see if it
does the next step. You might not even need the close statement,
since that stops execution of the expect process which is the
parent to the shell script. If you do need the close statement,
have it wait until the script echos some message.
Old 06-05-2011, 09:57 PM   #3
LQ Newbie
Registered: Jun 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
The expect "You" WOrked a treaT!

Weird, but perhaps the bash terminal was too fast or the other way round..

Anyhow all good, have moved on with my script now



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] run expect script within another script Linux - Newbie 7 01-21-2011 06:35 AM
Create BASH script to process multiple inputs on read davisbase Linux - Newbie 5 05-27-2010 12:57 AM
How do I make my BASH script yes/no user input query terminate with 3 invalid inputs? lupusarcanus Linux - Newbie 9 03-16-2010 04:43 PM
expect script to change user password sherimm Linux - Software 1 03-13-2009 06:36 AM
Shell Script - Change user & run multiple commands ijf99 Linux - Newbie 1 01-26-2009 07:15 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:44 AM.

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