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)
use "without prompting" options
Why not just add "without prompting" to your restore command. It eliminates the prompt.
did you try this without the while loop?
echo "y" | db2 .....
Otherwise, check the db2 command man page to turn off interactive mode.?