Operating System - HP-UX
1753788 Members
7353 Online
108799 Solutions
New Discussion юеВ

Replying to prompts within a script

 
SOLVED
Go to solution
MikeL_4
Super Advisor

Replying to prompts within a script

I want to run a command within a script, but the command requires a reply:

# gfs_tool reclaim /gfs/saweb
Don't do this if this file system is being exported by NFS (on any machine).

Are you sure you want to proceed? [y/n] n
gfs_tool: aborted
#

Is there a way to code this command in a script to supply it with a "y" to continue on ???
3 REPLIES 3
Matti_Kurkela
Honored Contributor
Solution

Re: Replying to prompts within a script

It is possible to write a program in such a way that it defeats simple I/O redirection (example: the "passwd" command), but I'd try this first:

echo y | gfs_tool reclaim /gfs/saweb

MK
MK
MikeL_4
Super Advisor

Re: Replying to prompts within a script

Matti

Thanks, I wasn't even thinking of something so simple would work...
Don Mallory
Trusted Contributor

Re: Replying to prompts within a script

Sometimes that won't work.

If you have a lot of yeses, you could use "yes"...

yes | gfs_tool reclaim /gfs/saweb

Or, you can also do something like this:

gfs_tool reclaim /gfs/saweb << EOL
y
EOL

This will enter all of the replies in order. Works really well for configuring something larger too, like EMS. The example below would get you monitors for snmp, email and log outputs:

/etc/opt/resmon/lbin/monconfig << EOL
a
a
1
4
4
/var/opt/resmon/log/event.log
c
c
y
a
a
3
4
5
c
c
y
a
a
2
4
6
admins@mydomain.ca
c
c
y
a
a
3
5
3
c
c
y
a
a
4
5
3
c
c
y
a
a
5
5
3
c
c
y
e
q
EOL