Re: shell script question
- From: Jon LaBadie <jxlabadie@xxxxxxxxxx>
- Date: Sun, 03 Sep 2006 10:58:26 -0400
Mohsen Lashkariani wrote:
Hi,
I have written a shell script that is supposed to print column names in
each table in each database in a Sybase SQL Server, but for some reason
unknown to me, it failes to print information on columns. sp_help is system
stored procedure in Sybase SQL Server, which shall print the required
information. I can also get the same info from syscolumns, but sp_help
print-out is quite nice and I prefer that. I do appreciate, if somebody tell
me why does function columns () failes to print the output of sp_help.
Best regards,
Mohsen
============================================================================
============================
#!/bin/sh
# Get the name of databases
function dbList ()
{
/usr/bin/isql -Usa -P << EOF
use master
go
select name from sysdatabases order by name
go
EOF
}
# Print the tablenames in each database
function tableList ()
{
/usr/bin/isql -Usa -P << EOF
select name from ${1}.dbo.sysobjects where type = "U" order by name
go
EOF
}
# Print the property of columns
function columns ()
{
/usr/bin/isql -Usa -P << EOF
sp_help ${1}.dbo.${2}
go
EOF
}
# Get a list of databases in SQL server
dl=`dbList|egrep -v '(name|--|affected)'`
# Go through the database list and generate a list of tables within the
database
for dn in $ $dl
do
# Get a list of tables within the database
tl=`tableList $dn|egrep -v '(name|--|affected)'`
# Go through the list of tables
for tn in $tl
do
echo
echo
"---------------------------------------------------------------------------
------------------------------------------"
echo "$dn -- > $tn"
echo
"---------------------------------------------------------------------------
------------------------------------------"
# Generate data on the columns in the tables
cl=`columns $dn $tn`
echo $cl
you are losing any formatting that might be in the columns output
because you have not double quoted $cl
echo.
"===========================================================================
=========================="
echo
done
done
- Follow-Ups:
- Re: shell script question
- From: Mohsen Lashkariani
- Re: shell script question
- References:
- shell script question
- From: Mohsen Lashkariani
- shell script question
- Prev by Date: Re: How do you echo a carriage return?
- Next by Date: Re: How do you echo a carriage return?
- Previous by thread: Re: shell script question
- Next by thread: Re: shell script question
- Index(es):
Relevant Pages
|