Solved

error calling unix script

Posted on 2014-03-29
17
367 Views
Last Modified: 2014-04-21
Hi,
I am running below unix script as below

$ call test.sh
ksh: call:  not found
$

As i am not good in unix so please help me finish this.

#---- Set Environment
mdmdb="ABC"
mdmdbuser="USER"
mdmdbpwd="AAA"

#---- Connect to the Database
db2 connect to $mdmdb user $mdmdbuser using $mdmdbpwd

#
# Whatever you want to do goes here...
#
EXPORT TO
\userin\AA\TEST.ixf OF IXF
MESSAGES
\userin\AA\TEST.log
select * from SYSIBM.SYSDUMMY1

#---- Terminate DB2
db2 terminate
0
Comment
Question by:sam2929
  • 6
  • 5
  • 3
  • +2
17 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 39963701
run it as

. test.sh
0
 

Author Comment

by:sam2929
ID: 39963738
looks like we need to give db2 path name

test.sh[7]: db2:  not found
test.sh[12]: EXPORT:  not found
0
 
LVL 84

Expert Comment

by:ozo
ID: 39963774
Is `EXPORT` supposed to be a shell command, or are you trying to pass it as input to the db2 command?
0
 

Author Comment

by:sam2929
ID: 39964347
pass input to db2 command
0
 
LVL 48

Expert Comment

by:Tintin
ID: 39964349
#!/bin/sh
#---- Set Environment
mdmdb="ABC"
mdmdbuser="USER"
mdmdbpwd="AAA"
PATH=$PATH:/directory/of/db2
export PATH

#---- Connect to the Database
db2 connect to $mdmdb user $mdmdbuser using $mdmdbpwd <<EOF

#
# Whatever you want to do goes here...
#
EXPORT TO
\userin\AA\TEST.ixf OF IXF
MESSAGES
\userin\AA\TEST.log
select * from SYSIBM.SYSDUMMY1
EOF

#---- Terminate DB2
db2 terminate

Open in new window

0
 

Author Comment

by:sam2929
ID: 39965327
I am not sure what path is but i found old script where some thing like this is done before is it possible to find what the path is from below script


Open in new window

if [ $? -eq 0 ]
  then
   DSENV="DEV"
   SCRIPT_DIR=/opt/IBM/InformationServer/Server/Projects/test_dev/Data
   PWS_SSH_KEY=${SCRIPT_DIR}/.ssh/id_rsa-MII-Test  ; export PWS_SSH_KEY
   . /db2_src/db2roar/sqllib/db2profile
     db_name=dev ; export db_name
     USER_PWS=aaa ; export USER_PWS
     HOST_PWS=99.99.99.00 ; export HOST_PWS
     PWS_TARGET_DIR="/db2_database/db2extracts/ibmcom/NcDbFeeds/cdt" ; export PWS_TARGET_DIR
     # temporary, until UAT project is online :
     PWS_TARGET_DIR="/db2_database/db2extracts/ibmcom/NcDbFeeds/pre" ; export PWS_TARGET_DIR
     HOST_PWS=99.99.99.99; export HOST_PWS
0
 
LVL 4

Expert Comment

by:popesy
ID: 39966151
Hello

The path to the 'db2' command is not in that code you listed above.

To find out where your db2 command is run the following as root user;

find / -type f -name db2 -print

Open in new window


This should give you your path to the location of the command.  All you need to do is use the directory path.  Lets say the 'db2' command is located here,

/opt/ibm/db2db/cmds/db2

Open in new window


You set your $PATH to be,

$PATH=$PATH:/opt/ibm/db2db/cmds

Open in new window


Assuming you are coding it like Tintin suggests above.


Cheers, JP.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 39966199
Doing

. /db2_src/db2roar/sqllib/db2profile

is most likely setting the PATH and other required variables.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 19

Expert Comment

by:simon3270
ID: 39967088
Re the initial comment, I'd advise against running
. test.sh

Open in new window

in this case.  True, it is a quick way of running a script that doesn't have execute permission, but it runs in your shell's own environment, so any shell or environment variables that are changed will be changed in your interactive shell.  This is sometimes what you want, but in this case the script does some work and is not intended to set variables which are remembered after the script is run.  In particular, if it does something like "PATH=$PATH:/opt/ibm/db2db/cmds", then "/opt/ibm/db2db/cmds" will be added to your path every time you source the script, so that PATH will get longer and longer.

Better would be
bash test.sh

Open in new window

, assuming you are running a bash login shell.  If not, replace "bash" with whatever shell you are using.
0
 
LVL 84

Expert Comment

by:ozo
ID: 39968246
I agree.  It looked at first to me as if the script was intended to set  environment variables in your shell.
0
 
LVL 19

Expert Comment

by:simon3270
ID: 39968576
Me too - it was only later posts that told us it was an action script!
0
 

Author Comment

by:sam2929
ID: 40003570
getting below error now


#!/bin/sh
#---- Set Environment
mdmdb="AA"
mdmdbuser="BB"
mdmdbpwd="CC"
PATH=$PATH:/db2_src/db2ruin/sqllib/bin
export PATH

#---- Connect to the Database
db2 connect to $mdmdb user $mdmdbuser using $mdmdbpwd

#
# Whatever you want to do goes here...
#
EXPORT TO
/userin/Integration_dev/marketing_acct_em.ixf OF IXF
MESSAGES
/userin/Integration_dev/marketing_acct_em.log
select 'x' as id  from SYSIBM.SYSDUMMY1

EOF
      

#---- Terminate DB2
db2 terminate


test.sh[15]: EXPORT:  not found
test.sh[16]: /userin/Integration_dev/marketing_acct_em.ixf:  not found
test.sh[17]: MESSAGES:  not found
test.sh[18]: /userin/Integration_dev/marketing_acct_em.log:  not found
test.sh[19]: syntax error at line 19 : `as' unexpected
$
0
 
LVL 19

Expert Comment

by:simon3270
ID: 40003862
you are missing the

    <<EOF

at the end of the "db2 connect" line
0
 

Author Comment

by:sam2929
ID: 40004818
That worked but i didn't see below statment ixf or log file created in same directory

EXPORT TO
/userin/Integration_dev/marketing_acct_em.ixf OF IXF
MESSAGES
/userin/Integration_dev/marketing_acct_em.log
select 'x' as id  from SYSIBM.SYSDUMMY1
0
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 40006093
I've dug around a bit more (I don't have a db2 system I can try this on), but I think you've merged two ways of running db2 commands - one where you precede each command with "db2", and one where you don't.

Please try either of these:
db2 "connect to $mdmdb user $mdmdbuser using $mdmdbpwd"
db2 "EXPORT TO /userin/Integration_dev/marketing_acct_em.ixf OF IXF MESSAGES /userin/Integration_dev/marketing_acct_em.log select 'x' as id  from SYSIBM.SYSDUMMY1"
db2 terminate

Open in new window

or
db2 <<EOF
connect to $mdmdb user $mdmdbuser using $mdmdbpwd
EXPORT TO /userin/Integration_dev/marketing_acct_em.ixf OF IXF MESSAGES /userin/Integration_dev/marketing_acct_em.log select 'x' as id  from SYSIBM.SYSDUMMY1"
terminate
EOF

Open in new window

(this code replaces everything from your "db2 connect" line to your "db2 terminate" line)
0
 

Author Comment

by:sam2929
ID: 40008481
Below script works now
1)i want to encrypt the mdmdbpwd password how can i do that
2) I have another folder /userin/dev/archive i want to archive 10 days worth of file there with time stamp too.

#!/bin/sh
#---- Set Environment
mdmdb="EMMDB"
mdmdbuser="MKT_DBO"
mdmdbpwd="time44up"
#-----PATH=$PATH:/db2_src/db2ruin/sqllib/bin
#------export PATH
. /db2_src/db2ruin/sqllib/db2profile

#---- Connect to the Database
db2 connect to $mdmdb user $mdmdbuser using $mdmdbpwd 

#
# Whatever you want to do goes here...
#
db2 "EXPORT TO
/userin/MAT_Integration_dev/marketing_acct_em.ixf OF IXF
MESSAGES
/userin/MAT_Integration_dev/marketing_acct_em.log
select 'x' as id  from SYSIBM.SYSDUMMY1"

	

#---- Terminate DB2
db2 terminate

Open in new window

0
 
LVL 19

Expert Comment

by:simon3270
ID: 40009211
Excellent.

No idea how to encrypt your password, and not enough information to archive your files, but those are separate questions - this one's answered!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now