If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > how read the flat files from shell scripting

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-31-09, 07:56
shijoe shijoe is offline
Registered User
 
Join Date: Mar 2009
Posts: 13
how read the flat files from shell scripting

We are using sybase data base and we have the data base name called MasterDB. The data baase MasterDB contains 100's of tables like sample1, sample2, sample3...etc...sample100
To take the count of every table we have to execute the following commands

use MasterDB //DB name
go //execute command in sybase
select count(*) from sample1 // command to find the count of table
go //execute the command


This is the way to take count. Likewise manually we have to take 100 tables count...we have to automates this though shell scripts.

What I did here is, I write all table names in the flat file and trying to read the flat files from the scripts

#!/bin/ksh

PATH=temp/flat_file
srv=sybaseserver
uid=operator
log=$LOGS/rowcount.log
pwd=`cat $SYBASE/.operatorpwd`
CP_CONN="-U$uid -S$srv -C3433 -b100000"

echo "count of table Started at: `date`" > $log
echo >> $log

echo "-------------------------------------------------------" >> $log
echo 'Setting table count..' >> $log
isql -U$uid -S$srv << EOF >> $log
$pwd
use customers
go
print 'taking count from tables..'
go
while read line
do
select count(*) from $customer_table \n
go
done < outfile.dat

i know its incorrect logic..pls help me onthis
Reply With Quote
  #2 (permalink)  
Old 03-31-09, 10:28
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
Code:
#!/bin/ksh
srv=sybaseserver
uid=operator
log=$LOGS/rowcount.log
pwd=`cat $SYBASE/.operatorpwd`
gensel() {
isql -U$uid -S$srv -b -Dcustomers <<EOF
set nocount on
go
select 'select count(*) as '+name+' from '+name+char(10)+'go ' from sysobjects where type='U' and name like 'sample%'
go
EOF
}
isql -U$uid -S$srv -Dcustomers <<EOF >>$log
$(gensel)
EOF

Last edited by pdreyer; 03-31-09 at 10:35.
Reply With Quote
  #3 (permalink)  
Old 03-31-09, 10:34
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Cool No mixing

You are not allowed to MIX sql statements and shell commands.
Try this approach:
Code:
#!/bin/ksh

FILE_PATH=temp/flat_file
srv=sybaseserver
uid=operator
log=$LOGS/rowcount.log
pwd=`cat $SYBASE/.operatorpwd`
CP_CONN="-U$uid -S$srv -C3433 -b100000"
{
echo "$pwd"
echo "use customers"
echo "go"
} > $FILE_PATH/cmdfile.sql
while read customer_table
do
  echo "select '$customer_table count:' as table_name, count(*) from $customer_table"
  echo "go"
done < $FILE_PATH/outfile.dat >>$FILE_PATH/cmdfile.sql
echo "exit" >> $FILE_PATH/cmdfile.sql
## ---
echo "count of table Started at: `date`\n" > $log
echo "-------------------------------------------------------" >> $log
echo 'Setting table count..' >> $log
isql $CP_CONN <$FILE_PATH/cmdfile.sql >> $log
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #4 (permalink)  
Old 03-31-09, 12:17
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Quote:
Originally Posted by shijoe
We are using sybase data base and we have the data base name called MasterDB. The data baase MasterDB contains 100's of tables like sample1, sample2, sample3...etc...sample100
Just a comment - I don't think it's a good idea having a production database named almost the same as the master database in Sybase. At some point in the future someone's going to get the two confused and you'll have a disaster on your hands.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On