0

I'm trying shell script to automatically accept value as Y when prompted in script but somehow it always say "Operation cancelled at user request". The nid command is an Oracle utility DBNEWID for changing a database name.

Any idea on how to accept Y in below function? Function logs into database and changes name.

function rename_db {
nid target=SYS/"as sysdba" DBNAME=newdb << EOD
Y
EOD
}

Runtime output:

Change db ID and name to newdb? (Y/[N]) =>

Operation cancelled at user request

Community
  • 1
  • 1
homer
  • 423
  • 2
  • 11
  • 24
  • Can you try following: `echo 'Y' | nid target=SYS/"as sysdba" DBNAME=newdb` – devang Sep 11 '15 at 20:20
  • @gotuskar still receives same "Operation cancelled at user request" – homer Sep 11 '15 at 20:36
  • `printf "Y\r\n" | nid ...` ? good luck. – shellter Sep 12 '15 at 00:53
  • 1
    Is the stdin flushed by nid? Maybe you can start nid and let the Y being streamed few seconds later: `(sleep 3; echo "Y") | (echo start; while read x; do echo $x; done)` – Walter A Sep 12 '15 at 17:05
  • 1
    Thanks everyone for your comments and different variations to accept Y, somehow it didn't work. While reading more about nid I found out there is a parameter LOGFILE which if used accepts Y as automatically e.g. `nid target=sys/"as sysdba" dbname=old_db logfile=rename.log` – homer Sep 14 '15 at 17:46

2 Answers2

2

Use below, if we use logfile then it will accept Y as the default and never prompts.

e.g. nid target=sys/"as sysdba" dbname=old_db logfile=rename.log

homer
  • 423
  • 2
  • 11
  • 24
0

Do you have expect (https://en.wikipedia.org/wiki/Expect) installed? You would want to use that which is designed for this sort of thing.

toddlermenot
  • 1,588
  • 2
  • 17
  • 33