Using tools to minimize work

By Paul Murphy, author of The Unix Guide to Defenestration

If you've been gifted with a "PC compatible" database structure - meaning that the application implements schemas as small databases and you're stuck having to administer dozens of databases on one Unix server, a few simple tricks can make your life a lot easier.

The central idea is to have a tool -perl, awk, csh, or even sed; whatever you're more comfortable with, write repetitive SQL commands for you instead of either doing this within SQL or doing it manually.

For example if you have the following files:

% cat ~/bin/sql
/opt/dbs/sybase/bin/isql -Usa -Syour_dbgrp -Pyour_password -w80

% cat ~/dbtools/awk.create
BEGIN {print "use master" print "go"}
{print "create database "$1" on "$2"="$3" log on "$4"="1+int($3/2); print "go"}

% cat ~/dbtools/dbs.crt
database_name target_device_name dbs_size dbs_log_device

then:
% cd dbtools
% awk -f awk.createdb dbs.crt | sql

will recreate the system for you and, of course, you can use the same strategy to create tables, load the databases from backups, modify user permissions, or do any other repetitive task.