Another issue with crontab


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Another issue with crontab
# 1  
Another issue with crontab

My shell script it.sh
Code:
#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=`date "+%m-%d-%Y  %H:%M:%S"`; export today
CUR_DIR=$1; export CUR_DIR


LOG_FILE=$CUR_DIR/error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file 
SCRIPT_DIR=`cat $CUR_DIR/.id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat $CUR_DIR/.id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat $CUR_DIR/.id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat $CUR_DIR/.id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID


### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD<<EOF>$CUR_DIR/sql_output.txt
set feedback off
set heading off
select  1016 from adj where rownum <2;
EOF


if [ $? -eq 0 ] 
then 
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are  "



if [  ! -s  "$CUR_DIR/sql_output.txt" ]
then
echo "No account number for bad debt" 
else
for i in `cat $CUR_DIR/sql_output.txt`
do
echo "bip $i is running"
cd $SCRIPT_DIR
sh bip.sh 01 0 $i >  $CUR_DIR/bip_log_1.txt
sleep 100
done
fi


###Removing temporary log files generated 

if [  -f  $CUR_DIR/bip_log_1.txt ]
then
`rm  $CUR_DIR/bip_log_1.txt`
 echo "file bip__log_1.txt removed"
fi

if [  -f  $CUR_DIR/sql_output.txt ]
then
`rm  $CUR_DIR/sql_output.txt`
 echo "sql_output.txt removed"
fi

when i execute the script manually ,it is working fine but when i schedule this job in crontab i get an error in error.log

Why?
Please help me.

crontab entry

Code:
59 04 * * *  /arbor/integ_fx/rahul_raj/itsr_5652/it.sh /arbor/integ_fx/rahul_raj/itsr_5652

Code:
LOGGING STARTS 07-22-2013  05:22:00


SQLPLUS CONNECTION
 SQLPLUS Connection Successful
bip 1016 is running
cat: cannot open /.arborpw
file bip__log_1.txt removed
sql_output.txt removed

# 2  
change this

Code:
cd $SCRIPT_DIR
sh bip.sh 01 0 $i >  $CUR_DIR/bip_log_1.txt

to

Code:
sh  $SCRIPT_DIR/bip.sh 01 0 $i >  $CUR_DIR/bip_log_1.txt

# 3  
Quote:
Originally Posted by vidyadhar85
change this

Code:
cd $SCRIPT_DIR
sh bip.sh 01 0 $i >  $CUR_DIR/bip_log_1.txt

to

Code:
sh  $SCRIPT_DIR/bip.sh 01 0 $i >  $CUR_DIR/bip_log_1.txt


Hi i am still getting the same error
# 4  
I don't know what's going on with all this cat $CUR_DIR stuff.

Surely it should be more like
Code:
grep "^USER_ID" $CUR_DIR/.id_pass_file.txt | ...

CUR_DIR is surely a variable storing the "current directory", and not a file whose contents are to be prefixed to some string and piped to grep
# 5  
Quote:
Originally Posted by Scott
I don't know what's going on with all this cat $CUR_DIR stuff.

Surely it should be more like
Code:
grep "^USER_ID" $CUR_DIR/.id_pass_file.txt | ...

CUR_DIR is surely a variable storing the "current directory", and not a file whose contents are to be prefixed to some string and piped to grep

HI scott
Code:
SCRIPT_DIR=`cat $CUR_DIR/.id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat $CUR_DIR/.id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat $CUR_DIR/.id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat $CUR_DIR/.id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID

.id_pass_file.txt is a configuration file storing the password username ,sid and path of the shell script.i am just fetching the username ,password from them,.the cionnection is also successfull .But i dont understand the error that i am getting
# 6  
Ignore me, I think I'm sleep deprived!

Anyway, I've removed all the pointless cat's and replaced backticks with $() or removed pointless ones.

And added set -x for some trace. Please run it and post the output.

Code:
#!/bin/sh

set -vx

ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=$(date "+%m-%d-%Y  %H:%M:%S"); export today
CUR_DIR=$1; export CUR_DIR


LOG_FILE=$CUR_DIR/error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file 
SCRIPT_DIR=$(grep "^SCRIPT_DIR" $CUR_DIR/.id_pass_file.txt | cut -d "=" -f2)
export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=$(grep "^USER_ID" $CUR_DIR/.id_pass_file.txt | cut -d "=" -f2)
export USER_ID

PWD=$(grep "^PWD" $CUR_DIR/.id_pass_file.txt | cut -d "=" -f2)
export PWD

SID=$(grep "^SID" $CUR_DIR/.id_pass_file.txt | cut -d "=" -f2)
export SID


### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD << EOF > $CUR_DIR/sql_output.txt
set feedback off
set heading off
select  1016 from adj where rownum <2;
EOF


if [ $? -eq 0 ] 
then 
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are  "



if [  ! -s  "$CUR_DIR/sql_output.txt" ]
then
  echo "No account number for bad debt" 
  else
  while read LINE; do
    echo "bip $i is running"
    cd $SCRIPT_DIR
    sh bip.sh 01 0 $i > $CUR_DIR/bip_log_1.txt ### Append to this one file, or a new file for each one?
    sleep 100
  done < $CUR_DIR/sql_output.txt
fi


###Removing temporary log files generated 

if [ -f  $CUR_DIR/bip_log_1.txt ]
then
 rm  $CUR_DIR/bip_log_1.txt
 echo "file bip__log_1.txt removed"
fi

if [  -f  $CUR_DIR/sql_output.txt ]
then
 rm  $CUR_DIR/sql_output.txt
 echo "sql_output.txt removed"
fi

# 7  
Quote:
Originally Posted by Scott
Ignore me, I think I'm sleep deprived!

Anyway, I've removed all the pointless cat's and replaced backticks with $() or removed pointless ones.

And added set -x for some trace. Please run it and post the output.

Code:
#!/bin/sh

set -vx

ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=$(date "+%m-%d-%Y  %H:%M:%S"); export today
CUR_DIR=$1; export CUR_DIR


LOG_FILE=$CUR_DIR/error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file 
SCRIPT_DIR=$(grep "^SCRIPT_DIR" $CUR_DIR/.id_pass_file.txt | cut -d "=" -f2)
export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=$(grep "^USER_ID" $CUR_DIR/.id_pass_file.txt | cut -d "=" -f2)
export USER_ID

PWD=$(grep "^PWD" $CUR_DIR/.id_pass_file.txt | cut -d "=" -f2)
export PWD

SID=$(grep "^SID" $CUR_DIR/.id_pass_file.txt | cut -d "=" -f2)
export SID


### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD << EOF > $CUR_DIR/sql_output.txt
set feedback off
set heading off
select  1016 from adj where rownum <2;
EOF


if [ $? -eq 0 ] 
then 
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are  "



if [  ! -s  "$CUR_DIR/sql_output.txt" ]
then
  echo "No account number for bad debt" 
  else
  while read LINE; do
    echo "bip $i is running"
    cd $SCRIPT_DIR
    sh bip.sh 01 0 $i > $CUR_DIR/bip_log_1.txt ### Append to this one file, or a new file for each one?
    sleep 100
  done < $CUR_DIR/sql_output.txt
fi


###Removing temporary log files generated 

if [ -f  $CUR_DIR/bip_log_1.txt ]
then
 rm  $CUR_DIR/bip_log_1.txt
 echo "file bip__log_1.txt removed"
fi

if [  -f  $CUR_DIR/sql_output.txt ]
then
 rm  $CUR_DIR/sql_output.txt
 echo "sql_output.txt removed"
fi


Script did not ran
Code:
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
ORACLE_HOME=/var/opt/oracle/product/10g
+ export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
PATH=/arbor/integ_fx/bin:/bin:/var/opt/oracle/product/10g/bin:/usr/cobol/bin:/arbor/integ_fx/bin:/arbor/3p/python/bin:/arbor/3p/rosette/bin:/arbor/3p/xerces/bin:/arbor/3p/xalan/bin:/arbor/3p/ACE_wrappers/bin:/arbor/3p/perl/bin:/app/tuxedo/tuxedo9.0/bin:/usr/java/bin:/var/opt/oracle/product/10g/bin:/arbor/3p/pgsql/bin:/arbor/integ_fx/opcntr/agent/bin:/arbor/integ_fx/opcntr/cc/bin:/arbor/integ_fx/DataBlitz/bin:/usr/bin:/sbin:/usr/sbin:/var/opt/oracle/product/10g/bin:/arbor/integ_fx/bin:/bin:/var/opt/oracle/product/10g/bin:/usr/cobol/bin:/arbor/integ_fx/bin:/arbor/3p/python/bin:/arbor/3p/rosette/bin:/arbor/3p/xerces/bin:/arbor/3p/xalan/bin:/arbor/3p/ACE_wrappers/bin:/arbor/3p/perl/bin:/app/tuxedo/tuxedo9.0/bin:/usr/java/bin:/var/opt/oracle/product/10g/bin:/arbor/3p/pgsql/bin:/arbor/integ_fx/opcntr/agent/bin:/arbor/integ_fx/opcntr/cc/bin:/arbor/integ_fx/DataBlitz/bin:/usr/bin:/sbin:/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/ucb:/etc:.:/usr/local/bin:/opt/openv/netbackup/bin:/usr/lib/vxvm/bin:/opt/sfw/bin:/opt/csw/bin:/var/opt/oracle/product/10g/bin:/bin:/usr/bin
+ export PATH
today=$(d./it.sh: syntax error at line 7: `today=$' unexpected
integfx:/arbor/integ_fx/rahul_raj/itsr_5652>

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #509
Difficulty: Medium
Most programming languages allow you to use whitespace characters (space, tab, etc.) in a variable's identifier.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Crontab issue

Hello, I have a bash script that finds files older than 31 days and deletes them. I have this file loading into crontab to run everyday. It ran fine the first time i loaded it in, but now when I try to run it manually (bash file.sh) I get errors. Here is the script TIME=" -maxdepth 1... (6 Replies)
Discussion started by: jrymer
6 Replies

2. UNIX for Advanced & Expert Users

Crontab Issue

My colleague who was a sysadmin , has created a cron job script which collects logs and process them. The script works perfectly as per the defined time set by him. it works when we keep the timing as 55 05 * * * , whereas if we try to prepone the cron task is not getting executed. Where... (10 Replies)
Discussion started by: aravindj80
10 Replies

3. Shell Programming and Scripting

Crontab issue

hi, i have schduled a job through crontab, but it is not getting executed. bash-3.2$ crontab -l # Monthly Download (mm hh DD MM format) 35 05 01 04 * /home/ftpsrp/srpftp1/download/ofrdb/scripts/load_ofrdb.sh crr.sh here is the permission of the .sh files -rwxr--r-- 1 ftpsrp srp ... (7 Replies)
Discussion started by: lovelysethii
7 Replies

4. UNIX for Dummies Questions & Answers

Crontab Issue..!!!

Hi, I have a cronjob but it is not getting executed.Is there any ways to check whether crontab is working.I have put crontab -l and checked.It got listed.But it is not working. My Crontab is, * * * * * /ldesk/home/abc/source/compare.sh >/dev/null 2>&1 (1 Reply)
Discussion started by: gayisada
1 Replies

5. AIX

Crontab issue

Hi all, I'm having a problem with a crontab entry execution for a non root user. AIX version 5.3 user@host ~ $ oslevel -r 5300-10 cron status user@host ~ $ ps -ef | grep cron root 377044 1 0 Oct 27 - 0:22 /usr/sbin/cron cron entry for user user@host ~ $... (3 Replies)
Discussion started by: h@foorsa.biz
3 Replies

6. UNIX for Advanced & Expert Users

Crontab issue

We have configured a script to be run at specific time using crontab. # crontab -l 15 11 * * * VM_Count_V4.shas per the crontab entry script should run every day 11.15 a.m Every time when the script is executed i get a mail but when i run it using crontab it doesn't send any mail. However... (1 Reply)
Discussion started by: pinga123
1 Replies

7. Shell Programming and Scripting

Issue with crontab

I have a ksh script which will connect to a database and executes some sql scripts. If i run the ksh script it is working fine. But if i schedule it to run at a perticular time using cron the sql script is not running. The scriptl initially creates a spool file for sql script and then connects and... (12 Replies)
Discussion started by: Sriranga
12 Replies

8. Shell Programming and Scripting

crontab issue

Helo . I have 2.6.13-1.1526_FC4smp here. I am trying to make crontab execute my simple shell script, but noting happens. here is how i am testing this : $ pwd /home/oracle $ ls -l two* ls: two*: No such file or directory $ $ crontab -e crontab: installing new crontab $ $ crontab... (7 Replies)
Discussion started by: tonijel
7 Replies

9. UNIX for Advanced & Expert Users

crontab issue

I am adding a piece of code which adds entry in crontab ((in brown color)) \crontab -l > $tmpfile echo "Removing the cleanProcess entry if it already existed.." grep -v "cleanProcess.sh" $tmpfile > $newtmpfile lcnt=`grep -c "cleanProcess.sh" $tmpfile` echo... (4 Replies)
Discussion started by: crackthehit007
4 Replies

10. HP-UX

crontab issue

Dear Folks, i am new to hp-ux, i have a problem scheduling the crontab, The script is working fine at command prompt, but not working at cron, please find a solution for it , here are the logs and my schedule at cron: log after restarting crontab /var/adm/cron/log ! *** cron started *** ... (11 Replies)
Discussion started by: vaddi
11 Replies

Featured Tech Videos