Personal tools
You are here: Home DB2 Scripts DB2 Shell Scripts to DB2 Grant privileges for a user or group on a specified schema
Navigation
Log in


Forgot your password?
 
Document Actions

Grant privileges for a user or group on a specified schema

To execute the script you have to inform the following parameters:

  • database name
  • User or Goup
  • schema
  • Privileges

Example:

ksh grant_privs.ksh DB_X USER_X SCHEMA_X insert,delete,update,select


Script grant_privs.ksh

#!/bin/ksh
# Grant privileges for a user or group on a specified schema
#---------------------------------------------------------------------------------------------

. ~/sqllib/db2profile

NUMARGS=$#

if [[ $NUMARGS -ne "4" ]]; then
        echo "Usage: $0 database userid schema privilege,..."
        echo "SYSADM authority required."
        exit -2
fi

typeset -u SCHEMA=$3
$(db2 connect to $1)
STMT="db2 select tabname from syscat.tables where tabschema='$SCHEMA'"
TABLES_TO_GRANT=$($STMT|egrep -v "TABNAME|----|selected.")
for TAB in $TABLES_TO_GRANT; do
     cmd="db2 grant $4 on $3.$TAB to $2"
     echo $cmd
     ret=$($cmd)
     echo $ret
done



Security Awareness
Would you like your company to implement gamification into your security awareness program?





Polls