LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-02-2015, 01:44 AM   #1
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Rep: Reputation: Disabled
Error with Unix script


Hi,

I have a written a script:
Code:
#!/usr/bin/ksh
#--------------------------------------------------------------------------------------------------------------#
#qz='sqlplus barcqz/xdr56yhn@BARP2'
#wdc='sqlplus barcwdc/xdr56yhn@BARP2'
#--------------------------------------------------------------------------------------------------------------#
sqlplus barcqz/xdr56yhn@BARP2 <<EOF
update qz_dates set QZ_DT = sysdate;
update qz_dates_back set QZ_DT = sysdate;
update wdc_dates set WDCDATE = sysdate;
update WDC_PAY_EXRATE set WPESENTDATE = to_char(sysdate,'DD-MON-YY:HH:MI:SS') ;
update WDC_OU_STARTTIME set WOSBUSINESSDATE =sysdate;
commit;
exit
EOF

sqlplus barcwdc/xdr56yhn@BARP2 <<EOF
update WDC_PAY_EXRATE set WPESENTDATE=(substr(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),1,10)||'T'||substr(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),12,19));
commit;
exit
EOF
when i run this script on command prompt, it runs well, but when i schedule it in crontab, it gives an error as:

Code:
/devapp1_01/quartz/qzprod1/santosh/scripts/update_date.sh[6]: sqlplus:  not found.
/devapp1_01/quartz/qzprod1/santosh/scripts/update_date.sh[16]: sqlplus:  not found.
/devapp1_01/quartz/qzprod1/santosh/scripts/update_date.sh[6]: sqlplus:  not found.
/devapp1_01/quartz/qzprod1/santosh/scripts/update_date.sh[16]: sqlplus:  not found.
could someone please help on this?
 
Old 01-02-2015, 02:33 AM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,831
Blog Entries: 36

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
cron typically has an unset path. You should either manually set the $PATH for crontab or use the full path in your script e.g. (/usr/bin/sqlplus).

Code:
which sqlplus
 
Old 01-02-2015, 04:34 AM   #3
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
the complete path for sqlplus is:
Code:
barza_uat_app1[] /devapp1_01/quartz/qzprod1 > which sqlplus
/usr/oracle/client_11g/product/11.2.0/client11g/bin/sqlplus

should i include above complete path in script like this:
Code:
#!/usr/bin/ksh
#--------------------------------------------------------------------------------------------------------------#
#qz='sqlplus barcqz/xdr56yhn@BARP2'
#wdc='sqlplus barcwdc/xdr56yhn@BARP2'
SQL_PATH="/usr/oracle/client_11g/product/11.2.0/client11g/bin/"
#--------------------------------------------------------------------------------------------------------------#
/usr/oracle/client_11g/product/11.2.0/client11g/bin/sqlplus barcqz/xdr56yhn@BARP2 <<EOF
update qz_dates set QZ_DT = sysdate;
update qz_dates_back set QZ_DT = sysdate;
update wdc_dates set WDCDATE = sysdate;
update WDC_PAY_EXRATE set WPESENTDATE = to_char(sysdate,'DD-MON-YY:HH:MI:SS') ;
update WDC_OU_STARTTIME set WOSBUSINESSDATE =sysdate;
commit;
exit
EOF

/usr/oracle/client_11g/product/11.2.0/client11g/bin/sqlplus barcwdc/xdr56yhn@BARP2 <<EOF
update WDC_PAY_EXRATE set WPESENTDATE=(substr(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),1,10)||'T'||substr(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),12,19));
commit;
exit
EOF
 
Old 01-02-2015, 07:18 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
You could also modify the path inside the script once at the top:
Code:
export PATH=$PATH:/usr/oracle/client_11g/product/11.2.0/client11g/bin
 
1 members found this post helpful.
Old 01-03-2015, 08:52 PM   #5
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,831
Blog Entries: 36

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Yes, referencing by using the full path to the executable or including it in the PATH as unSpawn suggests.
 
1 members found this post helpful.
Old 01-05-2015, 12:11 AM   #6
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
Thanks a lot, have modified the script as :
Code:
#!/usr/bin/ksh
#--------------------------------------------------------------------------------------------------------------#
export PATH=$PATH:/usr/oracle/client_11g/product/11.2.0/client11g/bin
#qz='sqlplus barcqz/xdr56yhn@BARP2'
#wdc='sqlplus barcwdc/xdr56yhn@BARP2'
#--------------------------------------------------------------------------------------------------------------#
sqlplus barcqz/xdr56yhn@BARP2 <<EOF
update qz_dates set QZ_DT = sysdate;
update qz_dates_back set QZ_DT = sysdate;
update wdc_dates set WDCDATE = sysdate;
update WDC_PAY_EXRATE set WPESENTDATE = to_char(sysdate,'DD-MON-YY:HH:MI:SS') ;
update WDC_OU_STARTTIME set WOSBUSINESSDATE =sysdate;
commit;
exit
EOF

sqlplus barcwdc/xdr56yhn@BARP2 <<EOF
update WDC_PAY_EXRATE set WPESENTDATE=(substr(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),1,10)||'T'||substr(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),12,19));
commit;
exit
EOF
will wait for its next run, and will let you know if any issues appears.

Thanks a lot for all your help:-)
 
Old 01-05-2015, 11:17 PM   #7
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
in the logs i got below message after putting export path in script
Code:
Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory

Last edited by santosh0782; 01-05-2015 at 11:25 PM.
 
Old 01-05-2015, 11:24 PM   #8
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

do you normally set ORACLE_HOME (and possibly other variables) in your shell? If so, they will need to be set in the cron job too.

Evo2.
 
Old 01-05-2015, 11:30 PM   #9
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
crontab entry for this script is as:

Code:
10 6 * * * /devapp1_01/quartz/qzprod1/santosh/scripts/update_date.sh >>/devapp1_01/quartz/qzprod1/santosh/scripts/update_date.log 2>&1
 
Old 01-05-2015, 11:37 PM   #10
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,


ok, let me be explicit. What is the output of the following?
Code:
env | grep ORACLE
Evo2.
 
Old 01-05-2015, 11:52 PM   #11
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
output is:
Code:
barza_uat_app1[] /devapp1_01/quartz/qzprod1 > env|grep ORACLE
ORACLE_PATH=/usr/oracle/client_11g/product/11.2.0/client11g/bin
ORACLE_SID=BARP2
ORACLE_HOME=/usr/oracle/client_11g/product/11.2.0/client11g
 
Old 01-06-2015, 12:09 AM   #12
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,831
Blog Entries: 36

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Quote:
Originally Posted by santosh0782 View Post
output is:
Code:
barza_uat_app1[] /devapp1_01/quartz/qzprod1 > env|grep ORACLE
ORACLE_PATH=/usr/oracle/client_11g/product/11.2.0/client11g/bin
ORACLE_SID=BARP2
ORACLE_HOME=/usr/oracle/client_11g/product/11.2.0/client11g
Add those environment variables to your cron script next to PATH. As was mentioned by evo2 the cron environment doesn't source normal user login scripts so all of the environment variables you normally depend on don't exist. That's why you have to explicitly set them.

SAM
 
Old 01-06-2015, 12:14 AM   #13
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
ok, i have added those environment variables to my script next to PATH as:
Code:
#!/usr/bin/ksh
#--------------------------------------------------------------------------------------------------------------#
export PATH=$PATH:/usr/oracle/client_11g/product/11.2.0/client11g/bin
ORACLE_PATH=/usr/oracle/client_11g/product/11.2.0/client11g/bin
ORACLE_SID=BARP2
ORACLE_HOME=/usr/oracle/client_11g/product/11.2.0/client11g
#qz='sqlplus barcqz/xdr56yhn@BARP2'
#wdc='sqlplus barcwdc/xdr56yhn@BARP2'
#--------------------------------------------------------------------------------------------------------------#
sqlplus barcqz/xdr56yhn@BARP2 <<EOF
update qz_dates set QZ_DT = sysdate;
update qz_dates_back set QZ_DT = sysdate;
update wdc_dates set WDCDATE = sysdate;
update WDC_PAY_EXRATE set WPESENTDATE = to_char(sysdate,'DD-MON-YY:HH:MI:SS') ;
update WDC_OU_STARTTIME set WOSBUSINESSDATE =sysdate;
commit;
exit
EOF

sqlplus barcwdc/xdr56yhn@BARP2 <<EOF
update WDC_PAY_EXRATE set WPESENTDATE=(substr(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),1,10)||'T'||substr(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),12,19));
commit;
exit
EOF
is it correct now?
 
Old 01-06-2015, 12:20 AM   #14
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,831
Blog Entries: 36

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Quote:
Originally Posted by santosh0782 View Post
ok, i have added those environment variables to my script next to PATH as:
...
is it correct now?
Only trial and error will tell. Let it run again and see if it works. I don't use Oracle much so I can't be sure.

Last edited by sag47; 01-06-2015 at 12:21 AM.
 
Old 01-06-2015, 11:03 PM   #15
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
I am still getting the same error message:
Code:
Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Appending Error to a File in unix script Saratha Linux - Newbie 4 04-19-2013 04:19 AM
script to telnet unix to unix and do some task divyashree Programming 10 07-27-2012 03:28 AM
Unix script help javaholics Linux - General 2 04-20-2010 10:19 AM
Unix Script Help Need deven1174 Programming 41 11-06-2009 01:14 PM
How to schedule unix script periodically from unix os level??? gopi_20us Programming 2 03-11-2002 07:45 AM


All times are GMT -5. The time now is 06:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration