Operating System - HP-UX
1848585 Members
3553 Online
104033 Solutions
New Discussion

Skip sequence in HP-UX shell programming

 
M. Z. Harbi
Advisor

Skip sequence in HP-UX shell programming

Hi,
I wonder if I could set a step in a script where I can skip a step in the written program after a brief time. this is available in DOS, but I don't know if it is available in HP-UX. in other words, if the command line ask you whether you want to make a copy of something during a buckup process and you would like the system to have a default answer "no"..
is it possible..?
UNDERSTAND life. Do NOT just STAND UNDER it...
9 REPLIES 9
Tim D Fulford
Honored Contributor

Re: Skip sequence in HP-UX shell programming

I'm not so sure I understand the question. But here is a script with two steps which you can skip first (which is the default)

#!/usr/bin/ksh
echo "do you wish to do next thing y/n (default no) ==>"
read ans
if [ $ans -eq y ]
then
echo "this is the next step"
fi
echo "this is the 2nd step"

Regards

Tim
-
Donny Jekels
Respected Contributor

Re: Skip sequence in HP-UX shell programming

Mohammed,

welcome to the forum.

your questions is not easily understood. just tell us what you want done. its that simple.

anyway in shell scripting you can use the powerfull case (switch) command to do just what you would like to achieve.

..
..
# echo to screen what you want the user to do
printf "What would you like to do next:\c\n"
# \c will a ding sound to attract the users attention
# \n is a new line, where your script will wait for the user to enter something
# now let the user know they 2 choices y/n with no being default
printf "To continue with this step (Y/[N])\n"

read ans

case in $ans
y|Y)
do your next step;;
*)
exit 1;;
esac

# the case statement will only understand y or Y. anything else. will exit.

enjoy

live free or die
donny

"Vision, is the art of seeing the invisible"
Caesar_3
Esteemed Contributor

Re: Skip sequence in HP-UX shell programming

Hello!

If you want to use default this depend
on how you disign the script, you
can set the default to variable and use it.

Caesar
Fragon
Trusted Contributor

Re: Skip sequence in HP-UX shell programming

Hi all,my understanding of the question:

Before go to next step, system give a prompt "Do you want to continue? (Y/N)", this prompt will keep 10 seconds(for example) to wait a user to input 'Y' or 'N', if time exceed, system set the default input 'N' and go to next step.

I know the idea but I must take some time to write the script and test!
Just a monent...

:p
-ux
Balaji N
Honored Contributor

Re: Skip sequence in HP-UX shell programming

hi

is what you require, the same as what hpux (user houx) has interpreted.

if so, spwan a new shell which asks for the input in background and wait on the pid. spawn another shell and sleep for ten seconds or so,
if the first script returns a value first, kill the sleep script and proceed. if the sleep script returns first, the user hasnt responded in the pre-determined step. kill it and proceed with default option.
-balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
Massimo Bianchi
Honored Contributor

Re: Skip sequence in HP-UX shell programming

Hi,
to help us in doing the translation to hpux, would you tell us how you do in DOS?

Many of us used the dos (i began with dos 3.0), so i think we can understand better with the example.

HTH,
Massimo
John Meissner
Esteemed Contributor

Re: Skip sequence in HP-UX shell programming

to put a timeout type of sequence in a script you can use this:


choice=`line -t 30`

basically what the above line does is replaces a read statement in a script.
example:
echo "what is your name"
read name
echo $name #will respond with the entered answer

in the first case you could say
echo "enter name"
name=`line -t 30`
if [ "$name" = "" ]
then
echo "you did not enter your name"
fi
All paths lead to destiny
M. Z. Harbi
Advisor

Re: Skip sequence in HP-UX shell programming

Thank you everybody... you answers were very helpful, especially Mr. John Meissner's answer. I know that the question was not clear enough, but thank gog somebody understood it..

thank you all again..

regards,
M. Z. Harbi
UNDERSTAND life. Do NOT just STAND UNDER it...
M. Z. Harbi
Advisor

Re: Skip sequence in HP-UX shell programming

Hi again,

to understand better my previous question,
I want to write a program where there is this question:

do you want to continue? (y/n)

now, off course, there will be two cases, but if I want add a third case that lets the program wait for sometime (30 sec) and if there is no answer, it will set the default answer (no). and continue..

regards,
M. Z. Harbi
UNDERSTAND life. Do NOT just STAND UNDER it...