tags:

views:

97

answers:

3

Hi, I'm trying to make a bash script that's going to backup a db2 database and then restore it into a different database. The problem is that DB2 asks a (y/n) question, and I can't get an auto answer for it to work - it needs a y and carriage return.

I've tried the following line (and the yes command) tho it doens't work

#while true; do echo y; done | db2 restore database $SOURCE taken at $DB2TIME into $TARGET

after the restore database command is executed I get this output from db2:

SQL2528W  Warning!  Restoring to an existing database that is the same as the 
backup image database, but the alias name "######" of the existing database 
does not match the alias "$$$$$" of backup image, and the database name 
"#######" of the existing database does not match the database name "$$$$$" of 
the backup image.  The target database will be overwritten by the backup 
version.
Do you want to continue ? (y/n) 
A: 

did you try this without the while loop?

echo "y" | db2 .....

Otherwise, check the db2 command man page to turn off interactive mode.?

ghostdog74
I don't think that would produce a carriage return so it would still sit there. I was hoping that there would be a way to just tell db2 to default to yes in the same command "db2 restore database ... yes" but that doesn't work either.
edumike
A: 

Why not just add "without prompting" to your restore command. It eliminates the prompt.

Ian Bjorhovde
A: 

use "without prompting" options

Fuangwith S.
@Fuangwith S. ok that did it, I just needed to use that same command and put "without prompting" at the end. I was trying to do it the traditional UNIX way with `yes` and got distracted cos it wasn't working - anyway thanks!
edumike