Operating System - HP-UX
1833271 Members
3182 Online
110051 Solutions
New Discussion

Re: need help with scriping

 
SOLVED
Go to solution
hi_5
Frequent Advisor

need help with scriping

I have to put a startup script in the init.d to start an application, please help...for instance :
cd /usr/home/life
./life1 <--- give you a menu where you have to select a number.
1.yes
2.no
** how can i write it in such, it will automatically pick 1 instead of waiting for the user?
Please help
3 REPLIES 3
Rodney Hills
Honored Contributor
Solution

Re: need help with scriping

Usually input is from STDIN and you can do the following-

echo "1" | ./life1

HTH

-- Rod Hills
There be dragons...
Paul Murray_4
Frequent Advisor

Re: need help with scriping

It sounds as if you need to use the "line" command as this allows you to specify a timeout period, specified in seconds.

If the following example script is run interactively, the user is given a window in which to make a decision, else it will apply a default. If you take this approach, make sure the default value will not perform any unwanted actions.



#!/usr/bin/env ksh

echo "Please enter Y to continue (default=N) \c"
REPLY="$(line -t 30)"
case ${REPLY:="N"} in
Y|y) echo "Y was selected !!"
;;
N|n) echo "N was selected !!"
;;
*) echo "Invalid option !!"
;;
esac



Another alternative would be to check to see if the script is being run in an interactive session - if not, apply a default. For example:

#!/usr/bin/env ksh

if [ "$(ttytype)" = "" ]
then
# Non interactive session - ie cron or rc !
echo "Default of N has been applied !!"
else
echo "Enter 1 or 2 \c"
read REPLY
case ......
etc etc etc etc




Give that ago - they may allow you to do what you want within your scripts !!

Rgds,
Paul


Hey, nobody knows EVERYthing !!!
Kevin Wright
Honored Contributor

Re: need help with scriping

Whatever value the script is waiting for the user to enter is probably read into a variable...just comment out the part where it asks the user the question, and hard code the varible to 1.