How to automate user selection options in shell script?

Hi There,

I am trying to write a script which has to pick the prompted options by itself(i mean option to choose will be passed)

here is real scenario i am trying to do.
i have an executable(diagnos) which gets called in shell script, when the executable (diagnos) runs i get following as shown below:
now i have to select option 1 (1. - Test Vertex Payroll ........)
this selection should get automated without any user intervention.

Pls help me out to get this logic.
if you have any question pls let me know
Thanks in Advance.

###########################################
[armymgr@usncx105 utils]$ diagnos

Vertex Payroll Tax Q Series - Diagnostic Program

Select Diagnostic Function
--------------------------

    • Test Vertex Payroll Tax Q Series Payroll Database Connection
    • Test Vertex Payroll Tax Q Series Location Database Connection
    • Test Vertex Payroll Tax Q Series Calculation
    • Exit Program

Select:
####################################################

Did you try a redirection?

how do i do that, i am not aware of redirection, can u give me an quick example...

Read your shell's man page.

$ echo 1 > somefile
$ diagnos < somefile

or

$ echo 1 | diagnos
diagnos << option
1
option

google "Linux here document" to know how this works

I tried
echo 1 > opt1.txt
diagnos < opt1.txt

but this is giving endless loop of above options
i have to forcefully exit from script using ctrl C
once i select option 1, i vl again be asked for another user input, but i dont see that.
I am getting endless loop.
Pls help

Post your script, at least the relevant part.

See: Loops
example 11-15

Then bookmark the main page: Advanced Bash-Scripting Guide

:slight_smile:

below is the code i am using:

month=$1
year=$2
sid=$3
dd=`date '+%m_%d_%H_%M'`
hostname=`uname -a | awk '{print $2}' | awk -F "." '{print $1}'`

#######################################

cd  /mnt/oracle_stage_NAS/vertexR12_$1_$2
cd data
echo >> /mnt/oracle_stage_NAS/vertex_$1_$2_$3.txt
echo "//////////////////////////////////////////////////////////////////////////////////" >>  /mnt/oracle_stage_NAS/vertex_$1_$2_$3.txt
echo >> /mnt/oracle_stage_NAS/vertex_$1_$2_$3.txt

date >> /mnt/oracle_stage_NAS/vertex_$1_$2_$3.txt
echo " Vertex Monthly Update File version : qfpt.dat"



grep -i version qfpt.dat >> /mnt/oracle_stage_NAS/vertex_$1_$2_$3.txt

echo >> /mnt/oracle_stage_NAS/vertex_$1_$2_$3.txt
echo "//////////////////////////////////////////////////////////////////////////////////" >>  /mnt/oracle_stage_NAS/vertex_$1_$2_$3.txt
echo >> /mnt/oracle_stage_NAS/vertex_$1_$2_$3.txt

echo "dat file location for month $1 year $2 " >> /mnt/oracle_stage_NAS/vertex_$1_$2_$3.txt
pwd >> /mnt/oracle_stage_NAS/vertex_$1_$2_$3.txt

echo "Current Vertex Installed data update in $3 is as below:" >> /mnt/oracle_stage_NAS/vertex_$1_$2_$3.txt

cd /mnt/ora$3/apps/apps_st/appl/pay/12.0.0/vendor/quantum/utils
echo 1 > opt1.txt
diagnos < opt1.txt