Friday, September 30, 2011

Write script to create a report of attributes of table of Sybase.

#!/bin/sh

Today=`date '+%d-%m-%y'`
report="report.$Today.txt"

print_header()
{
 awk 'BEGIN{for(c=0;c<50;c++) printf "-"; printf "\n"}'
 echo $0 started on $Today at `date '+%r'`
 awk 'BEGIN{for(c=0;c<50;c++) printf "-"; printf "\n"}'
}
print_footer()
{
 awk 'BEGIN{for(c=0;c<50;c++) printf "-"; printf "\n"}'
 echo $0 ended on $Today at `date '+%r'`
 awk 'BEGIN{for(c=0;c<50;c++) printf "-"; printf "\n"}'
}

print_header >> $report

isql -U<UserName> -P<Password> -S<ServerName> -D<DBName> <<EOF >>$report
set nocount on
select * from <TableName> where 1=2
go
exit
EOF
print_footer >> $report
echo $report has been successfully created!

No comments :