Visit Our UNIX and Linux User Community


Needing to wait for a line on screen and then give input repeatedly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Needing to wait for a line on screen and then give input repeatedly
# 1  
Old 03-23-2011
Needing to wait for a line on screen and then give input repeatedly

So I have a weird question for my unix shell script. I wrote a shell script that does several things, but one of the things it does is call an executable. The executable then proceeds to start asking me questions, which it won't proceed until an input is entered. The answer to the questions is always the same (for my application) so I am hoping to automate this. So for instance, it would be:
What is your name?
<my input>John
What is your last name?
<my input>Doe
Where do you live?
<my input>Drury Lane
What do you know?
<my input>Nothing
So the question is, is there a way to automate these answers, and if so, how do I do this?
# 2  
Old 03-23-2011
Does "your application" read from standard input?

Code:
$ cat Script1
read a
read b
read c
read d

echo "a is $a"
echo "b is $b"
echo "c is $c"
echo "d is $d"

$ printf "John\nDoe\nDrury Lane\nNothing" | ./Script1
a is John
b is Doe
c is Drury Lane
d is Nothing

If not, there's always expect
# 3  
Old 03-23-2011
So two questions. The way I read what you are saying, I don't think my program reads from standard I/O. I am not sure if I really understood what you meant by that though. If you mean can I do cat program_name, no I can not.

As far as expect, the way I read it it seems like something that has to be installed on a server. How would I find out or is the only way is to ask one of the server people that manage it? This is a three-tier architecture and I am only on the application level.
# 4  
Old 03-23-2011
Some programs, particularly those that prompt for passwords, are written in a way that disallows input to be directed to them (the program authors have gone to special measures to stop input being directed from a file), unless your program is in this category, we can say it reads from standard I/O.

Another question: after the fixed set of answers (those we would like to automate) do you need to interact with the program from the keyboard (ie type any more commands in or input anything)?
# 5  
Old 03-24-2011
Hey, I figured out what you meant with the whole printf | program thing and it worked like a charm. I appreciate your help, you solved a dilemma we had here at the office for several months!!

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to give input once logged in to server in script

Hi , when i am logging to the server i need to give input of specific key like k or l or m etc. and then need to put enter. need to use this in script . please assist. (1 Reply)
Discussion started by: rupesh.bombale
1 Replies

2. Shell Programming and Scripting

Replace a string with each line from another file repeatedly

I don't know if it's been asked before but seems i gave up seeking. i have 2 files : file1.txt Monday XXXX Tuesday XXXX XXXX Wednesday Thursday XXXX XXXX is in every lines of file1.txt and i want to replace them with each line in file2.txt: home school cinema so output file is: ... (19 Replies)
Discussion started by: perseous
19 Replies

3. Shell Programming and Scripting

BASH - read does not wait for user input in some circumstances

Hello. I am running 2 scripts : script_1 and script_2 These scripts are run as root Script 2 contains : #!/bin/bash # # ~/bin/script_2 # E_BAD_PARAM=115 # date2stamp () { date --date "$1" +%Y-%m-%d___%H:%M:%S } # USER_NAME=$1 NB_PARAM=$# PARAM0=$0 (2 Replies)
Discussion started by: jcdole
2 Replies

4. Shell Programming and Scripting

function terminating if i give input as space or no input and enter

HI i have written a script to ask input from the user. this script should promote the user for y/n input. if user enters anyother input then y/n the script promotes him again. this below code is working fine for all the cases. except for space and enter " if i give space and enter it is... (2 Replies)
Discussion started by: BHASKARREDDY006
2 Replies

5. Shell Programming and Scripting

perl line needing a tweak

Hi Folks, I have a perl line that looks like this and it works fine as is, but I need it to expand a bid further. perl -aF, -ne 'printf "conf zone %2\$s delete host %s,,,$F\n",split/\./,$F,2 if /^hostrecord/ &&/\b10\.8\.(|1)\.\d/' hosts.csv this code the way it is does this 10.8.3.0... (10 Replies)
Discussion started by: richsark
10 Replies

6. Red Hat

command line tool to disable screen lock and/or screen saver

Hi, I have a simple question : how to disable screen lock and/or sreen saver with command line with RHEL5.4 ? (1 Reply)
Discussion started by: albator1932
1 Replies

7. Shell Programming and Scripting

Needing a line feed for windows app

I wrote a program to format data with awk. This file will goto a windows machine and loaded into a windows app. The vendor said adding a line feed would help, but it would work as is. I am already doing a /n, will putting on the /r give the windows person what he wants. Thanks. (5 Replies)
Discussion started by: benefactr
5 Replies

8. Shell Programming and Scripting

Can give the input to prompt using shell script

Hi, I want to send input to promt from shell script, this thing is possible. I give the one command `/usr/share/ssl/misc/CA -newreq` it needs some user input like password etc., but i need this input also from shell script but it does not works. `/usr/share/ssl/misc/CA -newreq` <<EOF... (2 Replies)
Discussion started by: Vaibhav Agarwal
2 Replies

9. UNIX for Dummies Questions & Answers

making a .sh wait for user input

I need a script to halt at the end and wait for the user to hit a key...could be any ket or enter. I know it can be done but I am just starting out.. Thanks (9 Replies)
Discussion started by: verystupid
9 Replies

10. UNIX for Dummies Questions & Answers

Wait for input

I got this from one of my instructors years ago and I use it constantly: echo "Press any key to continue\c" oldstty=$(stty -g) stty -icanon -echo min 1 time 0 dd bs=1 count=1 2>/dev/null stty "$oldstty" (0 Replies)
Discussion started by: keelba
0 Replies

Featured Tech Videos