Execution Problems with Crontab


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Execution Problems with Crontab
# 1  
Old 02-19-2013
Execution Problems with Crontab

Dear Folks,

I have written a shell script which internally connects to oracle database through sqplplus command line.

The script runs fine when run manually.

Now I am scheduling it to run (Linux environment) from crontab.

In crontab it is failing with an error:

sqlplus command not found

I have exported ORACLE_HOME path from inside the script, but still its failing.

Help!!!
# 2  
Old 02-19-2013
Can you show the entire command line from crontab?
Also, the script?
# 3  
Old 02-20-2013
Hi Joey,

The command line from crontab: (was running it yesterday)

44 16 19 02 * /infinys/infroot/STCTEST12/TESTING_IRB/translation_space_find.sh

The script (translation_space_find.sh):

Code:
export ORACLE_HOME='/oracle/app/oracle/product/11.2.0.client'
export DATABASE='stc_irb_usr/stcirbusr_stctest12@stctest12'
export FGRED="\033[31m"
export FGGREEN="\033[32m"
export BOLD="\033[1m"
export NORMAL="\033[m"
echo "Started counting number of records with trailing/leading spaces..."
 
#For counting trailing spaces block 
 
echo "\
set pagesize 0
select count(*) from itemtranslation
where regexp_like(translated_item, '^[ ]+.*');" |
sqlplus -s $DATABASE | read trail
echo -e $FGGREEN $BOLD "Number of ITEMTRANSLATION records with trailing spaces is:" $NORMAL
echo -e $FGRED $BOLD "$trail" $NORMAL
echo "\
set pagesize 0
select count(*) from itemtranslation where regexp_like(translated_item, '.*[ ]+$');" |
sqlplus -s $DATABASE | read lead
echo -e $FGGREEN $BOLD "Number of ITEMTRANSLATION records with leading spaces is:" $NORMAL
echo -e $FGRED $BOLD "$lead" $NORMAL

# 4  
Old 02-20-2013
Hi,

Use the below export after export ORACLE_HOME

export PATH=$ORACLE_HOME/bin:$PATH
# 5  
Old 02-20-2013
Hi MKR,

Thanks. Error got resolved after export PATH=$ORACLE_HOME/bin:$PATH

However, below issues persist:
1) Values retrieved from database are not being printed. (as checked in mail generated in /var/spool/mail).

i.e. Number of ITEMTRANSLATION records with trailing spaces is:

After this no values are printed, which means that the count is not retrieved from database.

2) Deeper in the script I have used some if blocks, eg.
Code:
if [ $v_count_1 = 0 ]
then
echo "something1"

Code:
elif [ $v_count_1 -gt 0 ]
then
echo "something2"

For these, the cron is throwing errors:

line 69: [: =: unary operator expected
line 93: [: -gt: unary operator expected

Could you please help resolve these also Smilie
# 6  
Old 02-20-2013
Here is a example

change
Code:
if [ $v_count_1 = 0 ]

to
Code:
if [ "$v_count_1" = 0 ]

Code:
#!/bin/sh
v_count_1=0
if [ "$v_count_1" = 0 ]
then
echo "something1"
else
echo "vicky"
fi


Last edited by Vikram_Tanwar12; 02-20-2013 at 04:01 AM..
# 7  
Old 02-20-2013
Quote:
Originally Posted by Vikram_Tanwar12
Here is a example

change
Code:
if [ $v_count_1 = 0 ]

to
Code:
if [ "$v_count_1" = 0 ]

Ahem... sorry, but both are wrong. If you want to compare strings you have to write:

Code:
if [ "$v_count_1" == "0" ]

Notice not only the quotes around BOTH values but also the double equal signs. It is like in C: single "=" is an assignment, double "==" is for comparison.

If you want to compare integer values use "-eq" instead:

Code:
if [ $v_count_1 -eq 0 ]

other integer comparisons are:

-eq (equal to)
-ne (not equal)
-lt (lower than)
-le (lower or equal)
-gt (greater than)
-ge (greater or equal)


@tamojitc:
You are probably falling for "Cron Problem Number One", parts of which you have by now corrected by setting the path. There is probably a file ".ora_env" or something such in the HOME-directory of the oracle-user. I suggest sourcing in this at the beginning of the script to set the rest of the oarcle-environment (instance name, etc.):

Code:
#! /bin/ksh

. ./path/to/oracle-users/home/.ora_env

<rest of the script>

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Execution problems

How to find a word in a directory which contains many files? i just want to count how many such words are present in all the files? This is the code which i tried for a single file echo "Enter the file name:" read file echo "Enter the word to search:" read word if then echo "The count... (4 Replies)
Discussion started by: Meeran Rizvi
4 Replies

2. HP-UX

Crontab Execution

Hi Guys, I need help to clear my doubt w.r.t Crontab execution. uname -a HP-UX myservername B.11.31 U ia64 1422528451 unlimited-user licenseI created a crontab entry to execute particular job on Saturday 11/15/2014 11:22 Below is the cron entry #refresh DEVDB from PRODDB 22 11 15 11 6... (6 Replies)
Discussion started by: rocky.community
6 Replies

3. Shell Programming and Scripting

Execution Problems

this my source file ************* fixed *************** Begin equipmentId : d9 processor : fox number : bhhhhhh Variable # 1: Id : 100 Type : 9 nType : s gType : 5f mType : 4 LField : England DataField : london Length ... (6 Replies)
Discussion started by: teefa
6 Replies

4. Shell Programming and Scripting

Problem with Job execution using crontab

Hi All, I am facing a problem with crontab.I made an entry in crontab like this 05 07 * * * /afs2/cdwfullacc/current/exe/cdw_generate_special_klant.sh > /afs2/cdwfullacc/current/scratch/cdw_gen_cron.log But job was not getting executed. Entry in crontab was made with same user by whom... (4 Replies)
Discussion started by: krishna_gnv
4 Replies

5. Shell Programming and Scripting

Execution of Unix script after every second without crontab

Hi, I have shell script "A" which is executing oracle pl/sql procedure and initiate its multiple threads at a time as below on given user value in an other script "B". I want to execute script "A" after every second with out cron tab as " A " will keep on executing after every second till... (1 Reply)
Discussion started by: saad.imran@gmai
1 Replies

6. Shell Programming and Scripting

Execution Problems!!

i have been working on this for a about 12 hours today say's end of file un expected any idea's using the bourne shell and its driving me nuts worked fine in bash but prof says make it work in bourne and good luck worth 13% any help would be awesome #!/bin/sh trap "rm mnt2/source/tmp/* 2>... (1 Reply)
Discussion started by: mrhiab
1 Replies

7. UNIX for Dummies Questions & Answers

Problem with Crontab execution

Hi I have shell script to excute the SQL script.And i have scheduled those shell script in crontab.But the Shell script is not running timely and i got the below error Crontab entry 15 05 17 7 * /export/home/vcpsapp/vcps/stat.sh Output Your "cron" job on uspxivus16... (3 Replies)
Discussion started by: mak_boop
3 Replies

8. UNIX for Dummies Questions & Answers

Unscheduled crontab execution

Hi All, Do apologise, for it has been a long while since I was last on the forum. I've been doing documentation and primiarily Windows efforts for some while now. :( We are running a HP-UX 11.23 unit. This morning two separate crontab users executed shutdown scripts of their respective... (14 Replies)
Discussion started by: Cameron
14 Replies

9. UNIX for Dummies Questions & Answers

Execution problems with crontab

I need your help please Inin a production system i found crontab entries was removed because i typed crontab -l with username corasc and didn't show anything. i asked the administrador to restored the mentioned crontab, he restored the crontab: The problem is when restored the crontab file is... (2 Replies)
Discussion started by: alexcol
2 Replies

10. Shell Programming and Scripting

crontab execution

is it possible to soecify time overnight in 5 days for example: 0 18-7 * * 1-5 /mycode is this okay to use 18-7 because im not getting the results correctly? (4 Replies)
Discussion started by: vadharah
4 Replies
Login or Register to Ask a Question