There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer blue screen boot bsod computer connection crash css dell display driver drivers email error ethernet excel firefox firefox 3 game hard drive hardware internet internet explorer itunes laptop linux malware monitor network networking outlook outlook 2003 outlook express partition password printer problem problems ram router slow sound trojan usb video virus vista windows windows xp wireless
UNIX/Linux
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Operating Systems > UNIX/Linux >
scripting question


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
jlanier03's Avatar
Junior Member with 1 posts.
 
Join Date: Jun 2005
Experience: Advanced
07-Jun-2005, 05:06 PM #1
scripting question
I'm trying to come up with a shell script that will select a count from a table, compare that to a specific number, then based on the compared results call another script. Kind of like this


select count(*) from tableA
if (count from above) > 500000
then execute scriptsB

any ideas?
Squashman's Avatar
Distinguished Member with 12,700 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
07-Jun-2005, 08:51 PM #2
I would need to see the table to make any attempt at this.
codejockey's Avatar
Senior Member with 1,410 posts.
 
Join Date: Feb 2002
08-Jun-2005, 12:41 AM #3
A lot depends on what database/SQL interface you are using. You might consider (1) using a here document to run your SQL query or (2) (if your command-line SQL interface supports it), using back-tics to run the command and collect the output. Some RDBMSs will not accept stdin that is piped from another process, so you can't use a construct such as: cat command-file | sql -- even though the same RDBMS is perfectly happy with the same commands entered interactively (Sybase behaves this way, for example). In such cases, you may be able to use a construct such as sql < command-file to execute your sql commands. If so, you can always write the output to a file (e.g., sql < command-file > sql.out) and parse the output file contents in your script.

Hope this helps. More info appreciated.
__________________
The slowest component still sits at the keyboard.
codejockey's Avatar
Senior Member with 1,410 posts.
 
Join Date: Feb 2002
11-Jun-2005, 12:38 AM #4
Quote:
Some RDBMSs will not accept stdin that is piped from another process, so you can't use a construct such as: cat command-file | sql -- even though the same RDBMS is perfectly happy with the same commands entered interactively (Sybase behaves this way, for example).
I sit corrected. As it happens, today I discovered through a bit of experimentation that Sybase will, in fact, accept commands in a pipeline, but it's a bit of work: you must embed the newline character at the proper location(s) in the commands contained in the pipeline. For example, to display information about the columns (fields) of a table named "employee", you might use:

echo "sp_columns employee\ngo" | sql ....

Just wanted to set the record straight.
__________________
The slowest component still sits at the keyboard.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 03:56 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.