sam2929
asked on
error calling unix script
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
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
ASKER
looks like we need to give db2 path name
test.sh[7]: db2: not found
test.sh[12]: EXPORT: not found
test.sh[7]: db2: not found
test.sh[12]: EXPORT: not found
Is `EXPORT` supposed to be a shell command, or are you trying to pass it as input to the db2 command?
ASKER
pass input to db2 command
#!/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
ASKER
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
then
DSENV="DEV"
SCRIPT_DIR=/opt/IBM/Inform ationServe r/Server/P rojects/te st_dev/Dat a
PWS_SSH_KEY=${SCRIPT_DIR}/ .ssh/id_rs a-MII-Test ; export PWS_SSH_KEY
. /db2_src/db2roar/sqllib/db 2profile
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_datab ase/db2ext racts/ibmc om/NcDbFee ds/cdt" ; export PWS_TARGET_DIR
# temporary, until UAT project is online :
PWS_TARGET_DIR="/db2_datab ase/db2ext racts/ibmc om/NcDbFee ds/pre" ; export PWS_TARGET_DIR
HOST_PWS=99.99.99.99; export HOST_PWS
if [ $? -eq 0 ]then
DSENV="DEV"
SCRIPT_DIR=/opt/IBM/Inform
PWS_SSH_KEY=${SCRIPT_DIR}/
. /db2_src/db2roar/sqllib/db
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_datab
# temporary, until UAT project is online :
PWS_TARGET_DIR="/db2_datab
HOST_PWS=99.99.99.99; export HOST_PWS
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;
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,
You set your $PATH to be,
Assuming you are coding it like Tintin suggests above.
Cheers, JP.
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
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
You set your $PATH to be,
$PATH=$PATH:/opt/ibm/db2db/cmds
Assuming you are coding it like Tintin suggests above.
Cheers, JP.
Doing
. /db2_src/db2roar/sqllib/db 2profile
is most likely setting the PATH and other required variables.
. /db2_src/db2roar/sqllib/db
is most likely setting the PATH and other required variables.
Re the initial comment, I'd advise against running
/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
. test.sh
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/db2dbBetter would be
bash test.sh
, assuming you are running a bash login shell. If not, replace "bash" with whatever shell you are using.
I agree. It looked at first to me as if the script was intended to set environment variables in your shell.
Me too - it was only later posts that told us it was an action script!
ASKER
getting below error now
#!/bin/sh
#---- Set Environment
mdmdb="AA"
mdmdbuser="BB"
mdmdbpwd="CC"
PATH=$PATH:/db2_src/db2rui n/sqllib/b in
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/ma rketing_ac ct_em.ixf OF IXF
MESSAGES
/userin/Integration_dev/ma rketing_ac ct_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/ma rketing_ac ct_em.ixf: not found
test.sh[17]: MESSAGES: not found
test.sh[18]: /userin/Integration_dev/ma rketing_ac ct_em.log: not found
test.sh[19]: syntax error at line 19 : `as' unexpected
$
#!/bin/sh
#---- Set Environment
mdmdb="AA"
mdmdbuser="BB"
mdmdbpwd="CC"
PATH=$PATH:/db2_src/db2rui
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/ma
MESSAGES
/userin/Integration_dev/ma
select 'x' as id from SYSIBM.SYSDUMMY1
EOF
#---- Terminate DB2
db2 terminate
test.sh[15]: EXPORT: not found
test.sh[16]: /userin/Integration_dev/ma
test.sh[17]: MESSAGES: not found
test.sh[18]: /userin/Integration_dev/ma
test.sh[19]: syntax error at line 19 : `as' unexpected
$
you are missing the
<<EOF
at the end of the "db2 connect" line
<<EOF
at the end of the "db2 connect" line
ASKER
That worked but i didn't see below statment ixf or log file created in same directory
EXPORT TO
/userin/Integration_dev/ma rketing_ac ct_em.ixf OF IXF
MESSAGES
/userin/Integration_dev/ma rketing_ac ct_em.log
select 'x' as id from SYSIBM.SYSDUMMY1
EXPORT TO
/userin/Integration_dev/ma
MESSAGES
/userin/Integration_dev/ma
select 'x' as id from SYSIBM.SYSDUMMY1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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
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!
No idea how to encrypt your password, and not enough information to archive your files, but those are separate questions - this one's answered!
. test.sh