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