LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Crontab Script Confirmation (http://www.linuxquestions.org/questions/linux-newbie-8/crontab-script-confirmation-845828/)

stodds 11-22-2010 11:08 AM

Crontab Script Confirmation
 
Hey all,

I have a quick question involving crontab and a script I want to run with it. The script generates and sends an email to group members who are on-call for a given day, but when you run it this appears

'Run This Script?'

The script will run when you enter 'y' or 'yes' and then press enter.

I'm trying to give that input via another script which runs the first one and then waits for the prompt to input a 'y'

How can I make a script which waits for a prompt and then gives it input? I'm stuck on this... and if there is a better way to do it please let me know.

udaman 11-22-2010 11:24 AM

Bash script? Perl script?

use the "expect" function in bash to wait for a reply.

Code:

man expect

stodds 11-22-2010 11:31 AM

That looks like exactly what I want.

To give you more information, the script that makes/sends the emails is in perl (which I don't know very well, and wasn't written by me), and the script calling the perl is in bash.


So if I use expect in the bash script after calling the perl script I should be able to get it to give the perl script the ok to continue?


I do have one last question.
If I am replacing my shell script with an expect script that I want to run the perl and then give the perl input it'd look something like this right?


#!/bin/expect
spawn perl NAMEOFPERLSCRIPT.pl
expect "Run This Script?"
send "y"



Sorry for all the questions, expect is a new tool to me.

colucix 11-22-2010 12:01 PM

Another option: if the answer is always "yes" you can try the yes command as in:
Code:

yes | perl /path/to/script.pl
actually you can output any string with the yes command, but without any argument the default answer is 'y'. Hope this helps.

stodds 11-22-2010 12:09 PM

hmm... I like that second idea much better, and it should work because the answer always is yes.


All times are GMT -5. The time now is 03:35 PM.