標籤:
使用shell指令碼根據輸入的使用者名稱,資料庫名,密碼從DB2資料庫匯出資料
(1)a.sh指令碼如下
#!/usr/bin/bashread -p "please input your DBNAME: " DBNAMEread -p "please input your username: " usernameread -p "please input your password: " passworddb2 connect to $DBNAME user $username using $passworddb2 "EXPORT to /home/Practice/data/a.del of del select * from A"
(2)串連Linux,使用下面命令執行
su - db2inst1 -c "/home/Practice/a.sh"
上面這條代碼是關鍵,其中a.sh檔案儲存體在/home/Practice路徑下
[[email protected] Practice]# chmod +x a.sh[[email protected] data]# su - db2inst1 -c "/home/Practice/a.sh"please input your DBNAME: oliverdbplease input your username: db2inst1please input your password: db2inst1 Database Connection Information Database server = DB2/LINUXX8664 10.5.5 SQL authorization ID = DB2INST1 Local database alias = OLIVERDBSQL3104N The Export utility is beginning to export data to file "/home/Practice/data/a.del".SQL3105N The Export utility has finished exporting "2" rows.Number of rows exported: 2
到此處為止,資料已經從資料庫oiliverDB匯出到了目錄/home/Practice/data下。
使用shell從DB2資料庫匯出資料