Sponsored Content
Top Forums Shell Programming and Scripting Shell script with sql script error Post 303003533 by srilinux09 on Friday 15th of September 2017 11:08:45 AM
Old 09-15-2017
Solved

HI All

Thanks for looking at this .

I have solved this by using the following format

Code:
#!/bin/sh

dbname="test"
username="test"
psql $dbname $username << EOF
SELECT * FROM test;
EOF

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

passing parameter from Shell-script to Sql-script

Dear Friends, Please help me to achieve the following: I want to pass one parameter from Shell-script to Sql-script. Example: My ShellScript.sh is calling report.sql like this: /bin/sqlplus /reports.sql And My report.sql is calling many Stored-Procedures like this: exec... (0 Replies)
Discussion started by: subodhbansal
0 Replies

2. Shell Programming and Scripting

Calling SQL LDR and SQL plus scripts in a shell script

Hi- I am trying to achieve the following in a script so I can schedule it on a cron job. I am fairly new to the unix environment... I have written a shell script that reads a flat file and loads the data into an Oracle table (Table1) via SQLLDR. This Works fine. Then, I run a nested insert... (5 Replies)
Discussion started by: rajagavini
5 Replies

3. Shell Programming and Scripting

error connecting sql through a shell script

Hi I am getting this error while connecting to sql through a shell script, whereas i am able to connect to sql directly. It was working properly earlier, no clue why i am getting this. Please find the log below: FTP to <IP> completed Wed Apr 30 11:42:01 BST 2008 Program ended. Wed Apr 30... (1 Reply)
Discussion started by: nehak
1 Replies

4. Shell Programming and Scripting

Shell script which runs sql script

Hi all, I need a shell script which runs a sql script but I couldn't find how to finish it. This is the code that I have: #! /usr/bin/ksh export SHELL=/bin/ksh export ORACLE_SID=database export ORACLE_HOME=/opt/oracle/product/9.2.0.8 sqlplus user <<EOF @/path/path/path/scriptname.sql... (3 Replies)
Discussion started by: Geller
3 Replies

5. Shell Programming and Scripting

(Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script

Hi, I need help urgently for following issue. Pls help me to resolve this issue. I am calling sql script file(file1.sql) from UNIX Shell Script(script1.ksh) using sql plus and trying to create flat file that contains all records returned from SQL query in SQL script(file1.sql) I given... (6 Replies)
Discussion started by: praka
6 Replies

6. Shell Programming and Scripting

How to grep sql error in shell script and exit the script?

I need help in the following script. I want to grep the sql errors insert into the error table and exit the shell script if there is any error, otherwise keep running the scripts. Here is my script #!/bin/csh -f source .orapass set user = $USER set pass = $PASS cd /opt/data/scripts echo... (2 Replies)
Discussion started by: allinshell99
2 Replies

7. Shell Programming and Scripting

LIKE in SQL shell script

sqlplus -s <<__END__ ${USER}/${PASS}@${DB} WHENEVER SQLERROR EXIT SQL.SQLCODE ROLLBACK WHENEVER OSERROR EXIT FAILURE ROLLBACK SET ECHO ON SET TIMING ON SET SERVEROUTPUT ON SIZE 1000000 select count(*) from table where start LIKE '10-JUN-10'; EXIT __END__ result=$? echo $resultThis gives... (9 Replies)
Discussion started by: sandy1028
9 Replies

8. Shell Programming and Scripting

pass null value to sql script from korn shell script

There are 4 parameters that I have to pass from korn shell to sql script. 1) I have to check if $1 , $2 , $3 and $4 are null values or not . How can I do that ? 2) Once its determined that these values are null (in the sense they are empty) how can I pass null values to sql script... (11 Replies)
Discussion started by: megha2525
11 Replies

9. Shell Programming and Scripting

How to pass Oracle sql script as argument to UNIX shell script?

Hi all, $ echo $SHELL /bin/bash Requirement - How to pass oracle sql script as argument to unix shell script? $ ./output.sh users.sql Below are the shell scripts and the oracle sql file in the same folder. Shell Script $ cat output.sh #!/bin/bash .... (7 Replies)
Discussion started by: a1_win
7 Replies

10. Shell Programming and Scripting

Call sql script from UNIX shell script

I know this question is out there in many forums, but I tried all the combinations in vain. I'm basically trying to call a sql script from a shell script. Below is my sql script (plsql.sql) DELCARE v_empno NUMBER := '&empno'; BEGIN select ename,sal from emp where empno = v_empno;... (3 Replies)
Discussion started by: FName_LName
3 Replies
TAP::Parser::SourceHandler::pgTAP(3pm)			User Contributed Perl Documentation		    TAP::Parser::SourceHandler::pgTAP(3pm)

Name
       TAP::Parser::SourceHandler::pgTAP - Stream TAP from pgTAP test scripts

Synopsis
       In Build.PL for your application with pgTAP tests in t/*.pg:

	 Module::Build->new(
	     module_name	=> 'MyApp',
	     test_file_exts	=> [qw(.t .pg)],
	     use_tap_harness	=> 1,
	     tap_harness_args	=> {
		 sources => {
		     Perl  => undef,
		     pgTAP => {
			 dbname   => 'try',
			 username => 'postgres',
			 suffix   => '.pg',
		     },
		 }
	     },
	     build_requires	=> {
		 'Module::Build'		     => '0.30',
		 'TAP::Parser::SourceHandler::pgTAP' => '3.19',
	     },
	 )->create_build_script;

       If you're using "prove":

	 prove --source Perl 
	       --ext .t --ext .pg 
	       --source pgTAP --pgtap-option dbname=try 
			      --pgtap-option username=postgres 
			      --pgtap-option suffix=.pg

       If you have only pgTAP tests, just use "pg_prove":

	 pg_prove --dbname try --username postgres

       Direct use:

	 use TAP::Parser::Source;
	 use TAP::Parser::SourceHandler::pgTAP;

	 my $source = TAP::Parser::Source->new->raw('mytest.pg');
	 $source->config({ pgTAP => {
	     dbname   => 'testing',
	     username => 'postgres',
	     suffix   => '.pg',
	 }});
	 $source->assemble_meta;

	 my $class = 'TAP::Parser::SourceHandler::pgTAP';
	 my $vote  = $class->can_handle( $source );
	 my $iter  = $class->make_iterator( $source );

Description
       This source handler executes pgTAP tests. It does two things:

       1.  Looks at the TAP::Parser::Source passed to it to determine whether or not the source in question is in fact a pgTAP test
	   ("can_handle").

       2.  Creates an iterator that will call "psql" to run the pgTAP tests ("make_iterator").

       Unless you're writing a plugin or subclassing TAP::Parser, you probably won't need to use this module directly.

   Testing with pgTAP
       If you just want to write tests with pgTAP <http://pgtap.org/>, here's how:

       o   Build your test database, including pgTAP. It's best to install it in its own schema. To build it and install it in the schema "tap",
	   do this (assuming your database is named "try"):

	     make TAPSCHEMA=tap
	     make install
	     psql -U postgres -d try -f pgtap.sql

       o   Write your tests in files ending in .pg in the t directory, right alongside your normal Perl .t tests. Here's a simple pgTAP test to
	   get you started:

	     BEGIN;

	     SET search_path = public,tap,pg_catalog;

	     SELECT plan(1);

	     SELECT pass('This should pass!');

	     SELECT * FROM finish();
	     ROLLBACK;

	   Note how "search_path" has been set so that the pgTAP functions can be found in the "tap" schema. Consult the extensive pgTAP
	   documentation <http://pgtap.org/documentation.html> for a comprehensive list of test functions.

       o   Run your tests with "prove" like so:

	     prove --source Perl 
		   --ext .t --ext .pg 
		   --source pgTAP --pgtap-option dbname=try 
				  --pgtap-option username=postgres 
				  --pgtap-option suffix=.pg

	   This will run both your Perl .t tests and your pgTAP .pg tests all together. You can also use pg_prove to run just the pgTAP tests like
	   so:

	     pg_prove -d try -U postgres t/

       o   Once you're sure that you've got the pgTAP tests working, modify your Build.PL script to allow ./Build test to run both the Perl and
	   the pgTAP tests, like so:

	     Module::Build->new(
		 module_name	    => 'MyApp',
		 test_file_exts     => [qw(.t .pg)],
		 use_tap_harness    => 1,
		 configure_requires => { 'Module::Build' => '0.30', },
		 tap_harness_args   => {
		     sources => {
			 Perl  => undef,
			 pgTAP => {
			     dbname   => 'try',
			     username => 'postgres',
			     suffix   => '.pg',
			 },
		     }
		 },
		 build_requires     => {
		     'Module::Build'			 => '0.30',
		     'TAP::Parser::SourceHandler::pgTAP' => '3.19',
		 },
	     )->create_build_script;

	   The "use_tap_harness" parameter is optional, since it's implicitly set by the use of the "tap_harness_args" parameter. All the other
	   parameters are required as you see here. See the documentation for "make_iterator()" for a complete list of options to the "pgTAP" key
	   under "sources".

	   And that's it. Now get testing!

METHODS
Class Methods "can_handle" my $vote = $class->can_handle( $source ); Looks at the source to determine whether or not it's a pgTAP test and returns a score for how likely it is in fact a pgTAP test file. The scores are as follows: 1 if it's not a file and starts with "pgsql:". 1 if it has a suffix equal to that in the "suffix" config 1 if its suffix is ".pg" 0.8 if its suffix is ".sql" 0.75 if its suffix is ".s" The latter two scores are subject to change, so try to name your pgTAP tests ending in ".pg" or specify a suffix in the configuration to be sure. "make_iterator" my $iterator = $class->make_iterator( $source ); Returns a new TAP::Parser::Iterator::Process for the source. "$source->raw" must be either a file name or a scalar reference to the file name -- or a string starting with "pgsql:", in which case the remainder of the string is assumed to be SQL to be executed inside the database. The pgTAP tests are run by executing "psql", the PostgreSQL command-line utility. A number of arguments are passed to it, many of which you can affect by setting up the source source configuration. The configuration must be a hash reference, and supports the following keys: "psql" The path to the "psql" command. Defaults to simply "psql", which should work well enough if it's in your path. "dbname" The database to which to connect to run the tests. Defaults to the value of the $PGDATABASE environment variable or, if not set, to the system username. "username" The PostgreSQL username to use to connect to PostgreSQL. If not specified, no username will be used, in which case "psql" will fall back on either the $PGUSER environment variable or, if not set, the system username. "host" Specifies the host name of the machine to which to connect to the PostgreSQL server. If the value begins with a slash, it is used as the directory for the Unix-domain socket. Defaults to the value of the $PGDATABASE environment variable or, if not set, the local host. "port" Specifies the TCP port or the local Unix-domain socket file extension on which the server is listening for connections. Defaults to the value of the $PGPORT environment variable or, if not set, to the port specified at the time "psql" was compiled, usually 5432. "pset" Specifies a hash of printing options in the style of "pset" in the "psql" program. See the psql documentation <http://www.postgresql.org/docs/current/static/app-psql.html> for details on the supported options. See Also o TAP::Object o TAP::Parser o TAP::Parser::IteratorFactory o TAP::Parser::SourceHandler o TAP::Parser::SourceHandler::Executable o TAP::Parser::SourceHandler::Perl o TAP::Parser::SourceHandler::File o TAP::Parser::SourceHandler::Handle o TAP::Parser::SourceHandler::RawTAP o pgTAP <http://pgtap.org/> Support This module is managed in an open GitHub repository <http://github.com/theory/tap-parser-sourcehandler-pgtap/>. Feel free to fork and contribute, or to clone "git://github.com/theory/tap-parser-sourcehandler-pgtap.git" and send patches! Found a bug? Please post <http://github.com/theory/tap-parser-sourcehandler-pgtap/issues> or email <mailto:bug-tap-parser-sourcehandler- pgtap@rt.cpan.org> a report! Author David E. Wheeler <dwheeler@cpan.org> Copyright and License Copyright (c) 2010-2011 David E. Wheeler. Some Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-06-10 TAP::Parser::SourceHandler::pgTAP(3pm)
All times are GMT -4. The time now is 02:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy