How to run a remote database query?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to run a remote database query?
# 1  
Old 06-04-2013
How to run a remote database query?

Thank you for taking the time to read my issue. I need to set up a script to run from a wagon wheel type toplogy where 1 server needs to query about 10 to 15 remote servers for duplicate values in a database table. If a duplicate value is found, send an email to me( or wall command to console).
While it doesn't seem that hard in theory, I've been spinning my wheels as to how to even get started. I am very new to shell scripting and have been thrown into the fire by my supervisor.
I am working with Suse 11 Linux and sybase sql.

Any guidance would be most appreciated!
I at least have my database query;
Code:
select unit_address, count() from terminal group by unit_address having count() > 1

Smilie

Last edited by vbe; 06-04-2013 at 11:13 AM.. Reason: code tags please
# 2  
Old 06-04-2013
I have no idea what you can do with sybase ( too old since last time I worked with...) So I tell you what I would do in your case with an oracle DB, and I let you transpose...

I would put my query and oracle stuff in a oracle format sql script.
this script should generate a list for future processing...

I would then write a script that will call the oracle script for execution:
Code:
#Load required info for your remote database  by sourcing...
OUT=listing_name
DESTDIR=Working_dir...
.  ~ORA_profile
# GO is user/passwd...

sqlplus -silent $GO <<END
start $HOME/myoraclescript
exit;
END
if test -s "$OUT"
then
   echo found $OUT ". size not null"
   cat $OUT | sed 's/[ \t]*$//' > $DESTDIR$DESTFILE
   echo "File " $DESTFILE "generated in "$DESTDIR
else
   echo something went wrong
   if test -s "$HOME/sqlnet.log"
   then
      cat $HOME/sqlnet.log | ux2dos |\
      mailx -s "$HOST ALERT !! cannot connect to DB-$INSTANCE !! " \
      mail_addresses...
      > $HOME/sqlnet.log
   else
      mailx -s "$HOST: Bad,  something WENT WRONG !!" \
      mail_addresses...
   fi
   exit 2
fi
# Post processing using the output listing of previous...
# read content of listing looking for ??
if  [ duplicate found ]
then
   blah blah
   .
   .
fi


Last edited by vbe; 06-04-2013 at 12:55 PM.. Reason: finished the script I started but had to stop for work...
This User Gave Thanks to vbe For This Post:
# 3  
Old 06-05-2013
Thank you, VBE!

To be honest, that was kind of intimidating to read at first. I was able to come up with something easier for me to comprehend on the remote side. I have the remote servers set up with a shell script to query the database and write to a file if there are duplicate entries. It looks like this;
Code:
#!/bin/csh

~sybase/accisql raddude checkdupes  <<EOF > /export/home/radd6000/dup_UAs.txt
select unit_address, count() from terminal group by unit_address having count() > 1
go
EOF


So what is left is for me to make a script to go out from the main server to 10 remote hosts that have this duplicate check script on it and return some sort of alarm to me either via a wall command or email notice. Help me maybe?

---------- Post updated 06-05-13 at 05:57 AM ---------- Previous update was 06-04-13 at 02:11 PM ----------

Bump for awareness and I really need help......


Still trying to figure out how to create a shell script to ssh to several remote servers, check for file existence, if present, notify via wall command or email.
Smilie

The part I'm stuck on is how to set up the check of multiple servers.
# 4  
Old 06-05-2013
I guess, instead of doing SSH to every server , you can create Centralize storage (ISCSI) like (Shared Drive) which can be accessible to all the server and you can write your output file on this share drive like

Code:
 
/export/home/radd6000/dup_UAs_Servr1.txt
/export/home/radd6000/dup_UAs_Servr2.txt ...

And then create a shell script to check existance of this file and send mail.
This User Gave Thanks to pravin27 For This Post:
# 5  
Old 06-05-2013
Quote:
Originally Posted by pravin27
I guess, instead of doing SSH to every server , you can create Centralize storage (ISCSI) like (Shared Drive) which can be accessible to all the server and you can write your output file on this share drive like

Code:
 
/export/home/radd6000/dup_UAs_Servr1.txt
/export/home/radd6000/dup_UAs_Servr2.txt ...

And then create a shell script to check existance of this file and send mail.
How can I edit the current check to ftp the output to my central server if the file is present?

Code:
#!/bin/csh

~sybase/accisql raddude checkdupes  <<EOF > /export/home/radd6000/dup_UAs.txt
select unit_address, count() from terminal group by unit_address having count() > 1
go
EOF


Last edited by lutador72; 06-05-2013 at 11:05 AM..
# 6  
Old 06-05-2013
well I make the use of oracle sqlnet... in other words if the environment is correctly set, the script is executed local and via sqlnet, and so the output of the query is also local, dont you have such facility in Sybase?
If not the idea of prvain27 would be an alternative but means some administration making all servers seing a local directory accessible to them ( NFS mount...)

The easiest if you have nothing of the sort would be to write a script you put on each server and you use ssh user@$HOST <scriptname> to run the script
This User Gave Thanks to vbe For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Hierarchical Query for Sybase database

Team I am using DBartisan tool for sybase database. I have a table that has below fields Employee_ID,EMP_Name,First_Nm,Last_Nm,Emp_Designation,Employee's_Manager is it possible to retrieve hierarchical data based on below fields Emp_Designation will have Soft Engg,SSE,Team Lead,... (6 Replies)
Discussion started by: Perlbaby
6 Replies

2. Programming

Database query

I am getting an error function in date formate while importing the date ccolumn in oracle sql developer tool My date format in table is 6-Nov-14 and while importing its converted to 6/11/14 eventhough the format is as 6-Nov-14 in excel. could you please let help me out what I need to change... (6 Replies)
Discussion started by: ramkumar15
6 Replies

3. Shell Programming and Scripting

How to print multiple rows from database query?

HI, I am having scenario like to print multipule rows from output of database query sample query i mentioned below code=`db2 -x select code,values from dummy` in the query output i am getting around 110 records with 2 columns. sample output pasted below code,value... (3 Replies)
Discussion started by: bhaskar v
3 Replies

4. Shell Programming and Scripting

Help with script to create users from database query

#!/bin/bash user=`mysql userList -uuserlist -puserlistpassword -s -N -e "SELECT userName FROM users WHERE activated='n'"` for i in $user; do useradd "$i" -m doneThis is what I have done so far. But obviously it still does not work. I'm trying to create users based on information stored in a... (5 Replies)
Discussion started by: bucketuk
5 Replies

5. Shell Programming and Scripting

How to run a SQL select query in Oracle database through shell script?

I need to run a SQL select query in Oracle database and have to capture the list of retrieved records in shell script. Also i would like to modify the query for certain condition and need to fetch it again. How can i do this? Is there a way to have a persistent connection to oracle database... (9 Replies)
Discussion started by: vel4ever
9 Replies

6. Programming

Oracle Database Query

How can i modify the below to search for the things i'm looking for during a certain time frame? select Node, NodeAlias, Summary, Tally, AlertKey, AlertGroup, Manager, Agent from mrtg_alerts where LastOccurrence > '5-Dec-2010' order by Manager desc; In this particular case, this query is... (3 Replies)
Discussion started by: SkySmart
3 Replies

7. Shell Programming and Scripting

To spool output from a database query

Hi all, I would want to spool file for a database query, however by using crontab, the file is not spooled. Below shows my script: ORACLE_HOME="/u01/oraprod/perpdb/10.1.0/db_1" OUTFILE="/tmp/invalid.out" FILE="$HOME/admin/scripts" $ORACLE_HOME/bin/sqlplus -s "/as sysdba"... (0 Replies)
Discussion started by: *Jess*
0 Replies

8. Shell Programming and Scripting

Database Query

Hi, Am using informix database. When i give "isqlrf <database name> - " from the command prompt , i get connected to the database and i can run sql queries.. I am moving to freeBSD and when i give the same command at the prompt i get an error : Index already exists on column Why is this... (0 Replies)
Discussion started by: jisha
0 Replies

9. Shell Programming and Scripting

query to get a value from database

Hi friends, I have written a script which retrieves one value from the database. It takes time for the sql query to get the desired output. So the query runs fine from TOAD or from UNIX console. However if I put this in a script it doesn't work. The script is as below. #! /bin/ksh... (2 Replies)
Discussion started by: vivek_damodaran
2 Replies

10. Shell Programming and Scripting

storing database query in a variable

I am executing a SQL query in Unix Server: select status,location from user_information where request_id='DS-43720' In shell script I am writing this query in the below manner: echo "select status,location from user_information where request_id='DS-43720' ;" >> $directory/info.sql ... (3 Replies)
Discussion started by: debu
3 Replies
Login or Register to Ask a Question