Creating a query to Teradata using linux bash scripting

Database

Creating a query to Teradata using linux bash scripting

Hello all,

I'm hoping for some assistance in creating a script that will query a Teradata database.  The query needs to contain 2 seperate querys for 2 sepearte connections.  The first connection (Database 1) will do a row count on a specified table then return that count.  The 2nd query (DB 2) will connect to another database then do a row count for a specified table.  I want to see both of these counts as the result of the script.

Specifically, I am creating this script for a probe in Sitescope.  

3 REPLIES
Enthusiast

Re: Creating a query to Teradata using linux bash scripting

From bteq ref document. You can modify or customize  as per your requirement.

This line usually is #!/bin/bash as per Linux installer. You can validate if bash is set thus.

--#!/bin/sh

#!/bin/bash

bteq <<EOI

export DATADIR=/datasvc/data

.LOGON mydbs/myid,mypw;

.EXPORT REPORT FILE=$DATADIR/output

SELECT * from table_name;

.EXPORT RESET

.LOGOFF

.EXIT

EOI

So your select can be something like 'select count(*) from Database1.table1.....'

'select count(*) from Database2.table2.....'

I guess your Database2 is under same env, else under the same script, you need to do bteq  twice with different credentials.

export file then is different. If it is just seeing the result, no need the export part. Just logon 

to bteq and run the queries.

Re: Creating a query to Teradata using linux bash scripting

I do not currently have BTEQ installed on the Sitescope server.  

I have the JDBC driver installed, which allows me to connect to the database.  I beleive sqlplus is currently installed on the server.  Do I have to use BTEQ?  

Enthusiast

Re: Creating a query to Teradata using linux bash scripting

I am not pretty much aware of your Sitescope server. I do not know if ssh authentication and execution can be done remotely, from  another server. Maybe you can see if the feature of remote connection execution is possible. These days, I have seen many Network monitoring tools such as Ganglia,Monit, Munin, Collectd,Nagios...server monitoring tools that give good interaction. All information can be obtained from one house esp monitoring part. Execution part , like extracting extra info from another server, I have not tried. But I believe thin extra info can be done. Just my thought.