Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crontab

Status
Not open for further replies.

malpa

Technical User
Feb 8, 2004
122
CO
Hi

My programm run well using command line /bin/bash connection.sh, but when I used crontab programm this programm do not function.

messagge "Connection failed"


I would like to solve it.


Finally
What is the difference between at command and crontab command.
I am using at command for this job and it work well.

at -f ./conexion.sh 3:16 pm May 10,2010


Using crontab command

crontab -l
* 14 * * * ($HOME/.profile;/bin/bash $HOME/conexion.sh > $HOME/out4)

file connection.sh

#!/bin/bash
export ORACLE_HOME=/opt/oracle/10
export ORACLE_SID=bgw
export LD_LIBRARY_PATH=$ORACLE_HOME/lib32
export LD_LIBRARY_PATH_64=$ORACLE_HOME/lib


fecha_actual=`perl -e '($y,$m,$d) = (localtime(time() )) [5,4,3]; printf("%04d%02d%02d",$y + 1900,$m + 1,$d);'`
fecha_anterior=`perl -e '($y,$m,$d) = (localtime(time() - (1 * 86400) )) [5,4,3]; printf("%04d%02d%02d",$y + 1900,$m + 1,$d);'
`
echo $fecha_actual" "$fecha_anterior
dia=`echo $fecha_actual|awk -F"," ' { printf"%0+2s", $1 } '`
dia_at=`echo $fecha_anterior|awk -F"," ' { printf"%0+2s", $1 } '`
mes_at=`echo $fecha_anterior|awk -F"," ' { printf"%0+2s", $2 } '`
ano_at=`echo $fecha_anterior|awk -F"," ' { printf"%0+4s", $3 } '`
echo $dia_at
mes=`echo $fecha_actual|awk -F"," ' { printf"%0+2s", $2 } '`
ano=`echo $fecha_actual|awk -F"," ' { printf"%0+4s", $3 } '`
hora=`echo $fecha_actual|awk -F"," ' { printf"%0+2s", $4 } '`
min=`echo $fecha_actual|awk -F"," ' { printf"%0+2s", $5 } '`
seg=`echo $fecha_actual|awk -F"," ' { printf"%0+2s", $6 } '`
echo $?
sqlplus -s /nolog > /dev/null 2>&1 <<EOF
whenever sqlerror exit failure
connect user/pass@bgw
exit success
EOF

[ $? -ne 0 ] && { echo "Connection failed"; exit 1; }
echo "Connection succeeded"

sqlplus -s user/pass@bgw <<EOF
WHENEVER SQLERROR exit 5
whenever oserror exit 102
set linesize 1000
set pagesize 50000
set trimspool on
set colsep ';'
set long 20
set flush off
set feedback off

alter session set nls_date_format='YYYY-MM-DD';


spool $HOME/central_${dia}_${mes}_${ano}.txt
select XXXXXXXXXXXXXXXX;
/

spool off
exit
EOF
echo $?



Thanks
malpa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top