Hi everyone,
I am new to unix and bash and in need of some help.
I am writing a script that will execute a SQL query. The script runs and the SQl query runs, but I cannot figure out how to save the results as a file that can be emailed to a user. Here is my scripts thus far:
Thanks!
Moderator's Comments:
Please use code tags, thank you!
Last edited by Franklin52; 08-24-2010 at 01:34 PM..
Hi ,
I just found you while surfing for the string
'Redirecting sql select query output from within a shell script to txt file/excel file'
Could you find time sending me the code for the above question?
It'll be great help for me.
I have a perl file that calls the sql file... (1 Reply)
Hi Yogesh,
Lucky that i caught you online. Yeah i read about DBI and the WriteExcel module. But the server is not supporting these modules. It said..."Cannot locate DBI"..."Cannot locate Spreadsheet::WriteExcel"
I tried creating a simple text file to get the query output, but the... (1 Reply)
Hello Guys...
I want a small help from you guys.
Actually in Oracle, we are having a utlity called spool through which can store whatever SQL statements executed and other queries and the output of those queries in a file
So, similarly in Unix, if I start a session executing a number of Unix... (2 Replies)
Hello,
I run a web hosting company, and I'm wondering how I can use cPanel's Cron Jobs so that a copy of my entire home directory and a copy all of my MySQL databases can be compressed and emailed to me. I know nothing about Linux, Unix, or whatever that thing with the penguin is called. :)
... (7 Replies)
Hi
I need help on this. Its very urgent for me.. please try to help me out..
I have data in tables in DB2 database. I would like to export the data from DB2 tables into a text file, which has to be space delimited. so that I can carry out awk, grep operations on that file. I tried to export... (2 Replies)
I'm having problems with writing my sql results to a file:
sqlplus -S username/password@DB <<!!
set echo off
set verify off
set showmode off
set feedback off
set timing off
set linesize 250
set wrap off
set pagesize 0
set newpage none
set tab off
set trimspool on
set colsep... (1 Reply)
Hi
I want ot save SQL query result in one txt file. for that i have written one code line
sqlplus -s $dbstring @/usr/local/bin/sched/nightly_Cronjob/exec_123.sql >> /usr/local/bin/sched/nightly_Cronjob/result.txt
but it is not working .
database : Oracle
so please advice me how can i... (7 Replies)
Hi,
I am facing issues while exporting the results retrieved from the Database to an excel file.
I have 5 count query in order to count the records in 5 different tables.
I had connected to the DB and retrieved the column count and printed in the screen.
But wat I need to do is, I... (8 Replies)
Hello All,
I am writing the below unix script to email the result of a small pl sql procedure:
#!/bin/bash
ORACLE_HOME=/opt/oracle/orcts/product/9.2.0; export ORACLE_HOME
SQLPLUS=$ORACLE_HOME/bin/sqlplus
sqlplus -s user/pass@Db_instance<<EOF
set echo off
set feedback off
set pages 0... (9 Replies)
Discussion started by: Bunty bedi
9 Replies
LEARN ABOUT DEBIAN
stag-selectall_xml
SELECTALL_XML(1p) User Contributed Perl Documentation SELECTALL_XML(1p)NAME
stag-selectall_xml - Query all elements from database with an XML output
SYNOPSIS
stag-selectall_xml [-d <dbi>] [-f file of sql] [-nesting|n <nesting>] SQL
DESCRIPTION
This script will query a database using either SQL provided by the script user, or using an SQL templates; the query results will be turned
into XML using the DBIx::DBStag module. The nesting of the XML can be controlled by the DBStag SQL extension "USE NESTING..."
EXAMPLES
stag-selectall_xml -d "dbi:Pg:dbname=mydb;host=localhost"
"SELECT * FROM a NATURAL JOIN b"
TEMPLATES
A parameterized SQL template (canned query) can be used instead of specifying the full SQL
For example:
stag-selectall_xml -d genedb /genedb-gene gene_symbol=Adh
Or:
stag-selectall_xml -d genedb /genedb-gene Adh
Or:
stag-selectall_xml -d genedb /genedb-gene gene_symbol@=Adh,dpp,bam,indy
A template is indicated by the syntactic shorthand of using a slash to precede the template name; in this case the template is called
genedb-gene. the -t option can also be used.
All the remaining arguments are passed in as SQL template parameters. They can be passed in as either name=value pairs, or as a simple list
of arguments which get passed into the template in order
To use templates, you should have the environment variable DBSTAG_TEMPLATE_DIRS set. See DBIx::DBStag for details.
LISTING AVAILABLE TEMPLATES FOR A DB
stag-selectall_xml -d mydb -h
LISTING VARIABLES FOR A TEMPLATE
stag-selectall_xml /genedb-gene -h
ENVIRONMENT VARIABLES
DBSTAG_DBIMAP_FILE
A file containing configuration details for local databases
DBSTAG_TEMPLATE_DIRS
list of directories (separated by :s) to be searched when templates are requested
COMMAND LINE ARGUMENTS
-h|help
shows this page if no other arguments are given
if a template is specified, gives template details
if a db is specified, lists templates for that db
use in conjunction with -v for full descriptions
-d|dbname DBNAME
this is either a full DBI locator string (eg dbi:Pg:dbname=mydb;host=localhost) or it can also be a shortened "nickname", which is then
looked up in the file pointed at by the environment variable DBSTAG_DBIMAP_FILE
-u|user USER
database user identity
-p|password PASS
database password
-f|file SQLFILE
this is a path to a file containing SQL that will be executed, as an alternative to writing the SQL on the command line
-n|nesting NESTING-EXPRESSIONS
a bracketed expression indicating how to the resulting objects/XML should be nested. See DBIx::DBStag for details.
-t|template TEMPLATE-NAME
the name of a template; see above
-wh|where WHERE-CLAUSE
used to override the WHERE clause of the query; useful for combining with templates
You can append to an existing where clause by using the prefix +
-s|select SELECT-COLS
used to override the SELECT clause of the query; useful for combining with templates
-rows
sometimes it is preferable to return the results as a table rather than xml or a similar nested structure. specifying -rows will fetch
a table, one line per row, and columns separated by tabs
-pre SQL
a piece of SQL is that is executed immediately before the main query; e.g.:
-pre "SET search_path=myschema,public"
-o|out FILE
a file to output the results to
-w|writer WRITER
writer class; can be any perl class, or one of these
xml [default]
sxpr
lisp S-Expressions
itext
indented text
-color
shows results in color (sxpr and itext only)
-show
will show the parse of the SQL statement
perl v5.12.4 2011-10-14 SELECTALL_XML(1p)