LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 06-05-2011, 05:16 AM   #1
zoonose
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:
test.sh
Code:
#!/bin/bash
echo "Begin"
echo "==============="
/usr/bin/expect - << EOD
#!/usr/local/bin/expect
# Comments on this script (name, what it does,
# optional)
spawn /bin/bash
expect ":"
send "./include.sh\r"
expect "name"
send "Me\r"
expect "like"
send "Pizza\r"
close
EOD
echo "==============="
echo "Fin"
and include.sh
Code:
#!/bin/bash
echo "Name & Favourites Routine ..."
echo "What is your name?"
read ANSWER
echo "Your answer: $ANSWER"
echo "What do you like?"
read LIKE
echo "You love to: $LIKE"
exit
But when i run "./test.sh" from the command line, I receive the following:
Code:
Begin
===============
spawn /bin/bash
User@MacBook ~: ./include.sh
Name & Favourites Routine ...
What is your name?
Me
Your answer: Me
What do you like?
===============
Fin
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?

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

Rep: Reputation: 99
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, 08:57 PM   #3
zoonose
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

thx!
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:05 PM.

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