Operating System - HP-UX
1827495 Members
3190 Online
109965 Solutions
New Discussion

Scripting interactive command.

 
Gulam Mohiuddin
Regular Advisor

Scripting interactive command.

I have to run the following command on unix command line:

nid TARGET=sys/password@TSH1 DBNAME=TSH2

But this command runs interactively and asks me to enter (Y/[N]) as follows:

Change database ID and database name TSH1 to TSH2? (Y/[N]) =>


I scripted it in a file to pass the value 'Y' as follows:

#!/usr/bin/sh
ORACLE_SID=TSH1 ; export ORACLE_SID
nid TARGET=sys/password@TSH1 DBNAME=TSH2
Y
exit 0


But it didn't work, still asks me:

Change database ID and database name TSH1 to TSH2? (Y/[N]) =>

How to pass 'Y' in the script?


Thanks,

Gulam.
Everyday Learning.
6 REPLIES 6
Peter Godron
Honored Contributor

Re: Scripting interactive command.

Gulam,
have you tried a redirect?
echo "Y" > answers.lis
nid TARGET=sys/password@TSH1 DBNAME=TSH2 < answers.lis

renarios
Trusted Contributor

Re: Scripting interactive command.

Hi Gulam,

You can try the here doc:
#!/usr/bin/sh
ORACLE_SID=TSH1 ; export ORACLE_SID
nid TARGET=sys/password@TSH1 DBNAME=TSH2 <Y
exit
EOF

Cheers,

Renarios
Nothing is more successfull as failure
Patrick Wallek
Honored Contributor

Re: Scripting interactive command.

Try something like this:

#!/usr/bin/sh
ORACLE_SID=TSH1 ; export ORACLE_SID
nid TARGET=sys/password@TSH1 DBNAME=TSH2 << EOF
Y
EOF
exit 0

Senthil Kumar .A_1
Honored Contributor

Re: Scripting interactive command.

Hi Gulam,


Yep the answer is Here statemnet.

Follow Patricks instruction. Note there should be a space between "<<" and "EOF". secondly the exit should be after the second EOF, as it is not a response your nid program awaits.

Regards,
Senthil Kumar .A
Let your effort be such, the very words to define it, by a layman - would sound like a "POETRY" ;)
Arturo Galbiati
Esteemed Contributor

Re: Scripting interactive command.

You can use the here-document feature:
#!/usr/bin/sh
ORACLE_SID=TSH1 ; export ORACLE_SID
nid TARGET=sys/password@TSH1 DBNAME=TSH2 << EOF
Y
EOF

For more info about here-document:
http://wks.uts.ohio-state.edu/unix_course/intro-110.html

HTH,
Art
Geoff Wild
Honored Contributor

Re: Scripting interactive command.

If the above don't work, then you may have to do this with expect:

http://hpux.ee.ualberta.ca/hppd/hpux/Tcl/expect-5.43/

I attached a sftp expect script

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.