0

I want to manage DB2 database on remote host executing bash script on local host.

#!/bin/bash
host="80.80.80.80"
user="db2inst1"

DBname=DBNAME
db2="/opt/db2/db2inst1/sqllib/bin/db2"

ssh -t $host bash -c "'
sudo -u $user $db2 connect to $DBname
sudo -u $user $db2 quiesce database immediate force connections
'"

I connect to the host and connect to the database. But it seems, that connection to DB resets after first command and I get next error:

Database Connection Information

 Database server        = DB2/LINUXX8664 9.7.7
 SQL authorization ID   = DB2INST1
 Local database alias   = DBNAME

SQL1024N  **A database connection does not exist**.  SQLSTATE=08003
Connection to 80.80.80.80 closed.

How to keep the connection to a DB permanently on?

1 Answers1

-1

The problem is that each sudo calls creates a subshell. It means, that each call is independent.

You are executing one call to create the connection to the database. The second one to quiesce the database. What you really need is a sequence of commands to execute:

sudo -u $user "$db2 connect to $DBname ; $db2 quiesce database immediate force connections"
AngocA
  • 7,655
  • 6
  • 39
  • 55
  • Not work. `sh: -c: line 0: unexpected EOF while looking for matching sh: -c: line 3: syntax error: unexpected end of file Connection to 216.121.3.232 closed. ./clone_base.sh: line 20: /opt/db2/db2inst1/sqllib/bin/db2: No such file or directory` – user2567728 Jul 22 '15 at 18:09