Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sysbase User Script

Status
Not open for further replies.

AppSpecialist

Programmer
Jul 6, 2001
64
CA
Does anyone know how to assign read access to a user for every table in a sybase database through a script. Or by the same token assign select access to all tables to a role and in turn grant this role to a user?

The script is needed to be generic so that I don't have to hard code table names.

Thanks
 
This below script should work in korn or posix shell. This script requires your password to be in a file, but you could also hardcode it or supply it as an argument. The user name, database name, grantee, and "grant" shown here are hardcoded, but they could also be arguments or environmental variables.
---------------------------
#!/bin/sh

export USER=sa
export SERVER=${DSQUERY}
PWORD=$(<.pswd)
DB=repos2

Run () {
print &quot;${PWORD}\n${1}\ngo\n&quot; | isql -w600 -S$SERVER -U$USER
}

DBList=$(print $(Run &quot;use $DB\ngo\nselect 'NAME:',name from sysobjects where type='U'&quot; $SERVER|grep NAME: | cut -d: -f2))

for Tbl in $DBList
do
Run &quot;grant update on $Tbl to public&quot;
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top