[oracle@hngdcrm xxx]$ vi xtest.sh
#!/bin/sh
sqlplus /nolog <<EOF
conn crm_owner_user/bss_crm_xxp1 as sysdba;
select city_code from bb_service_relation_t t where t.service_id=8073102026973775 and t.if_valid=1;
exit;
EOF;
--赋予权限,要不crontab不能执行,报Permission denied
[oracle@hngdcrm log]$ chmod 777 xtest.sh
[oracle@hngdcrm log]$ crontab -e
*/2 * * * * /home/oracle/xxx/xtest.sh >>/home/oracle/xxx/log/mylog.log 2>&1
[oracle@hngdcrm log]$ cat mylog.log
/home/oracle/xxx/xtest.sh: line 2: sqlplus: command not found //没有引入变量
[oracle@hngdcrm xxx]$ vi xtest.sh
#环境变量的引入
if [ -f /usr/local/tdneusoft/ORACLE_crm.profile ];then
# . /usr/local/tdneusoft/ORACLE_crm.profile
#source /home/oracle/.bash_profile
export ORACLE_BASE=/home/oracle/app;#export ORACLE_BASE
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0;
export ORACLE_SID=hngdcrm
export PATH=$ORACLE_HOME/bin:$PATH
fi
#引入系统环境变量
if [ -f /usr/local/tdneusoft/Runtime_64bit.profile ];then
. /usr/local/tdneusoft/Runtime_64bit.profile
fi
sqlplus /nolog <<EOF
conn crm_owner_user/bss_crm_xxp1 as sysdba;
update bb_service_relation_t t set t.city_code=t.city_code+1 where t.service_id=8073102026973775 and t.if_valid=1;
commit;
exit;
EOF;