Computing.Net > Forums > Unix > execute shell script in SP informix

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

execute shell script in SP informix

Reply to Message Icon

Name: TheOskMan
Date: March 27, 2008 at 13:04:35 Pacific
OS: Unix
CPU/Ram: P4
Product: Programming
Comment:

Hi!
I need execute a shell script whiting a SP.
Example:
Create procedure my_sp(...)
...
system "/home/myuser/myprogram.sh";
..
end procedure;

myprogram.sh inside...
unload to myarchive delimiter ","
select * from mytable;

This is a posible??

Sorry, my english is BAD!

Regards,
Oscar.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 27, 2008 at 19:43:41 Pacific
Reply:

Sorry, but this won't work. This syntax:

unload to myarchive delimiter ","
select * from mytable;

is an informix command - not a unix command. The operating system will not recognize load as a valid command.

You can embed unload into an informix program or a stored proecedure and then call the stored proecedure.

Probably the best way is executing the unload command from dbaccess or isql.

Also, you can execute dbaccess or isql commands from a unix shell script:


#!/bin/ksh

# set to your database name
DBNAME="mydatabasename"; export DBNAME

# use dbaccess or isql
INTERFACE_CMD="dbaccess"; export INTERFACE_CMD

# send to standard output
DBCOMMAND="$INTERFACE_CMD -e $DBNAME"; export DBCOMMAND

engine_up=$(onstat - | grep "Up" | wc -l)
if [ $engine_up -eq 0 ]
then
echo "Informix Engine must be Up to execute commands."
exit
fi

$DBCOMMAND << MSG
unload to myarchive delimiter ","
select * from mytable
MSG


0

Response Number 2
Name: TheOskMan
Date: March 28, 2008 at 07:19:30 Pacific
Reply:

Thanks for your reply.

execute perfect!!!

Regards,

Oscar.


0

Response Number 3
Name: TheOskMan
Date: March 28, 2008 at 12:24:19 Pacific
Reply:

Hi!!

2 more questions!!

This shell script, run perfectly with commands informix on tables for DBsystem

example:
select distinct 'Hi' from systables

but, does not run properly with temporal tables.

example:
select id,name from tmp_myTable;

where tmp_myTable was create:

select * from TABLE
into temp tmp_myTable with no log;
----------
Gives the following error:

exception : looking for handler
SQL error = -668 ISAM error = -1

WHY?

string conection:
$INTERFACE_CMD -e $DBNAME

I need connect with user/pass, this is posible?

Regards,
Oscar.


0

Response Number 4
Name: nails
Date: March 29, 2008 at 14:07:26 Pacific
Reply:

QUESTION 1)
I am not having any problems. This works for me:

$DBCOMMAND << MSG
SELECT * FROM s_user INTO TEMP my_table WITH NO LOG;
SELECT * FROM my_table WHERE user_id = "nails"
MSG

Based on the -668 error, it looks like you don't have permission to create temporary tables.

QUESTION 2)

Every Unix version of Informix I've worked on, the dbaccess utility does not require a user or password. The Informix DBA controlled access using the Informix GRANT and REVOKE commands. Are you using the Window's version of Informix? If so, perhaps it requires a user and password?

I have absolutely no experience with the Window's version of Informix. Let's assume that dbaccess requires a -U for user option and a -P for password. You'll have to check. Then, consider something like this:


# ABSOLUTELY UNTESTED!!! eval maybe optional

DBCOMMAND="eval $INTERFACE_CMD -e $DBNAME -U $USER -P $PASSWD"

I have no idea whether the above string will work, and it is up to you to provide $USER and $PASSWD variables.



0

Response Number 5
Name: TheOskMan
Date: March 31, 2008 at 06:04:05 Pacific
Reply:

NAILS:

Thank´s very much.

I can´t understand this problem.

look:

Informix (Unix, i'm not using win):

SQL: New Run Modify Use-editor Output Choose Save Info Drop Exit
Run the current SQL statements.

select * from tmp_bas1
into temp mytt with no log;

10802 row(s) retrieved into temp table.

I have permission to create temporary tables.

Shell Script:

select * from mytt;

exception : looking for handler
SQL error = -668 ISAM error = -1

I appreciate your help.

Regards,
Oscar.


0

Related Posts

See More



Response Number 6
Name: nails
Date: March 31, 2008 at 12:46:17 Pacific
Reply:

A temporary table only exists for the life of your dbaccess/isql instance. Once you leave dbaccess, the temp table vanishes.

Post your script, and I'll look at it.


0

Response Number 7
Name: TheOskMan
Date: April 3, 2008 at 11:25:08 Pacific
Reply:

Hi Nails,

This is my shell script,

#!/bin/ksh
#
DBNAME="mydbname"; export DBNAME;

INTERFACE_CMD="dbaccess"; export INTERFACE_CMD;

# send to standard output
DBCOMMAND="$INTERFACE_CMD -e $DBNAME"; export DBCOMMAND;

engine_up=$(onstat - | grep "Up" | wc -l)

if [ $engine_up -eq 0 ]
then
"Informix Engine must be Up to execute commands"
exit
fi


$DBCOMMAND<< MSG
UNLOAD TO ARCHIVE2008.csv DELIMITER ","
SELECT DISTINCT "FIELD1","FIELD2","FIELD3","FIELD4" FROM SYSTABLES
UNION ALL
SELECT DISTINCT * FROM TMPUP;

MSG
exit


Thank´s
Regards,

Oscar.


0

Response Number 8
Name: nails
Date: April 4, 2008 at 11:26:30 Pacific
Reply:

Since I'm not at all familiar with your data I can only make a few guesses:

1) What is the table TMPUP? Based on the name, is it a temp table? I stated in an earlier post, temp tables only exist while your program - dbaccess in this case - is running. The only was your script will work is if TMPUP is a normal database table or if you create it in the same instance of $DBCOMMAND.

2) What is this???:

SELECT DISTINCT "FIELD1","FIELD2","FIELD3","FIELD4" FROM SYSTABLES

SYSTABLES is an informix system table containing information of the database's tables. FIELD1, FIELD2, etc. are not valid column names for this table.

I can't tell from your post, but are FIELD1, FIELD2, etc suppose to be shell variables?

If they are, you need a dollar sign in front:

$FIELD1, $FIELD2

Sorry, that's all I can tell you.


0

Response Number 9
Name: TheOskMan
Date: April 4, 2008 at 17:24:41 Pacific
Reply:

Hi Nails,

Let me be a little more clear.

1) TMPUP is my temp table.

2)select "HELLO" from systables;

Returns "HELLO"

The table SYSTABLES in Informix is similar to the table DUAL in ORACLE

select "HELLO" from DUAL return: "HELLO"

3)
"FIELD1", "FIELD2", etc, etc... are headed in my archive ARCHIVE2008.csv

4)Then

UNLOAD TO ARCHIVE2008.csv DELIMITER ","
SELECT DISTINCT "FIELD1","FIELD2","FIELD3","FIELD4" FROM SYSTABLES
UNION ALL
SELECT DISTINCT * FROM TMPUP;

return ARCHIVE2008.csv where

ARCHIVE2008.cvs is:

FIELD1,FIELD2,FIELD3,FIELD4
125, PAUL,Smith ,15934
126,ROBERT,Khan ,16545
. . . .
. . . .
. . . .
. . . .

Thank´s NAILS,
Regards,
Oscar.


0

Response Number 10
Name: nails
Date: April 7, 2008 at 18:00:02 Pacific
Reply:

OK, I understand what you are doing with systables. That should work.

However, what I said about the temporary table still goes.

$DBCOMMAND<< MSG
-- create temp table TMPUP before the unload
UNLOAD TO ARCHIVE2008.csv DELIMITER ","
SELECT DISTINCT "FIELD1","FIELD2","FIELD3","FIELD4" FROM SYSTABLES
UNION ALL
SELECT DISTINCT * FROM TMPUP;

MSG

The TMPUP temp table MUST be created in the same DBCOMMAND instance.



0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: execute shell script in SP informix

use variable of shell script in awk www.computing.net/answers/unix/use-variable-of-shell-script-in-awk/4570.html

Executing Shell scripts? www.computing.net/answers/unix/executing-shell-scripts/1304.html

execute shell file in other dir www.computing.net/answers/unix/execute-shell-file-in-other-dir/4754.html