免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4863 | 回复: 9

[求助] 我的cron作业不执行[已解决] [复制链接]

论坛徽章:
0
发表于 2012-02-14 16:49 |显示全部楼层
本帖最后由 山定子 于 2012-03-31 09:34 编辑

我在普通用户owr5000下用crontab -e建了个自动备份作业,即每周二15点50备份数据库内部文件:

50 15 * * Tue $OWHOME/bin/owbackup-all  /disk01/backups

在owr5000用户下的terminal窗口,在命令行下执行$OWHOME/bin/owbackup-all  /disk01/backups没有问题,但cron作业不执行(建完任务后也/sbin/service crond restart),不知问题出在哪里。


以下为机器中的一些信息:
wx02{owr5000}% ls `which crontab` -al
-rwsr-sr-x 1 root root 315432 Jul 15  2008 /usr/bin/crontab*

[root@wx02 cron]# ls -l /var/spool/cron/
total 4
-rw------- 1 owr5000 root 56 Feb 14 16:21 owr5000

[root@wx02 cron]# cat /var/spool/cron/owr5000
50 15 * * Tue $OWHOME/bin/owbackup-all /disk01/backups

wx02{owr5000}% chkconfig --list crond
crond           0ff   1ff   2n    3n    4n    5n    6ff

wx02{owr5000}% service crond status
crond (pid  17650) is running...

wx02{owr5000}% echo $shell
/bin/csh

论坛徽章:
0
发表于 2012-02-14 16:54 |显示全部楼层
你看你的crond服务启动了没?

论坛徽章:
0
发表于 2012-02-14 16:55 |显示全部楼层
下面没看到服务是运行的,不好意思。

论坛徽章:
0
发表于 2012-02-14 17:04 |显示全部楼层
回复 1# 山定子


    $OWHOME/bin/owbackup-all      别用变量 ,   命令x执行权限

论坛徽章:
0
发表于 2012-02-14 17:07 |显示全部楼层
谢谢split_two 和 taojie2000 ,我试一下看。

论坛徽章:
0
发表于 2012-02-14 17:31 |显示全部楼层
本帖最后由 山定子 于 2012-02-15 08:57 编辑

我把$OWHOME改为全路径/pb/OpenWorks,即10 17 * * Tue /pb/OpenWorks/bin/owbackup-all  /disk01/backups

owbackup-all为sh下的一个脚本(系统内置的),下面是它的权限:

wx02{owr5000}%  ls -al /pb/OpenWorks/bin/owbackup-all
-rwxr-xr-x 1 lmkadm lmk 12504 Aug 12  2011 /pb/OpenWorks/bin/owbackup-all*

可cron作业还是不执行。taojie2000 说的“别用变量”指的是什么?我第一次试用cron,不熟,在网上查了些帖子也没解决问题。希望能得到高手的帮助。

论坛徽章:
0
发表于 2012-02-14 18:27 |显示全部楼层
回复 1# 山定子


    内置的? owbackup-all 不是写的脚本? 如果写的脚本里面还要添加上环境变量        csh 用着不熟悉  

   

论坛徽章:
0
发表于 2012-02-15 09:29 |显示全部楼层
这是owbackup-all脚本中的一段注释:

# Notes:
#   To run this as a cron job, you must first set OWHOME, ORACLE_HOME,
#   and ORACLE_SID.  OWSYSSID also needs to be set if it isn't correct
#   in $OWHOME/conf/lgcenv.cf.

注释:若想做为cron job来运行该脚本,需首先设置OWHOME, ORACLE_HOME和ORACLE_SID。如果OWSYSSID在$OWHOME/conf/lgcenv.cf中不正确的话,也需要设置。
------------------------

查看了一下$OWHOME/conf/lgcenv.cf文件,设置都是正确的。不知还要设置什么才能执行cron job。

wx02{owr5000}% lgc_getenv OWHOME
/pb/OpenWorks

wx02{owr5000}% lgc_getenv ORACLE_HOME
/oracle/ora11g/product/11.2.0/dbhome_1

wx02{owr5000}% lgc_getenv ORACLE_SID
owpepris

wx02{owr5000}% lgc_getenv OWSYSSID
OWPEPRIS

论坛徽章:
0
发表于 2012-02-15 09:31 |显示全部楼层
这是owbackup-all脚本(Bourne Shell)内容:


wx02{owr5000}% more owbackup-all

#!/bin/sh

# Name:
#   owbackup-all - Backup all OpenWorks projects managed by the user.
#   
# Usage:
#   owbackup-all <directory_name> [<extension>]
#
#   The following one supports oracle with/without external file backup
#   owbackup-all <directory_name> -OEXT <oracle_file_extension>
#                -EXTFILEDIR <directory_name_to_store_External_Files>
# Examples:
#   $OWHOME/bin/owbackup-all /pa/backups
#   $OWHOME/bin/owbackup-all /export/home/backups -ow31.bck
#   
#   enhanced external file back up support
#   $OWHOME/bin/owbackup-all /export/home/backups -OEXT _ow31.bck
#          -EXTFILEDIR /export/home/backupExternal
# Arguments:
#   directory_name - directory the backup files will be created in
#   extension - extension for the backup file (.bck is the default)
# OR
# Arguments:
#   directory_name - directory the backup file will be created in
#   -OEXT <oracle_file_extension> the extension of the oracle backup file
#
#   -EXTFILEDIR <directory_name_to_saveTheExternalFile> the directory the external
#   file (OpenWorks project and seismic) back ups will be created in. if the user
#   provided the directory name for the external file backups, it means all the
#   external file backups should be done.
#                 
# Notes:
#   To run this as a cron job, you must first set OWHOME, ORACLE_HOME,
#   and ORACLE_SID.  OWSYSSID also needs to be set if it isn't correct
#   in $OWHOME/conf/lgcenv.cf.
#
# Description:
#   This is a batch interface to the Project Backup functionality of Project
#   Administration.  It backs up each project the user has manager access to
#   in the specified directory with a file name consisting of the project
#   name appended to the given extension (or .bck if no extension was
#   specified), i.e. TESTDATA.bck.
#
# Files/Databases:
#   - $OWHOME/conf/lgcenv.cf    OpenWorks Environment Variable File.
#
# Exit and Error Codes:
#   - 0 : Successful
#   - 1 : UnSuccessful
#
#
#----------------------------------------------------------------------------
#       Copyright (C) 2006 LANDMARK GRAPHICS CORP.
#       All rights reserved.
#============================================================================
# Added unset DISPLAY to solve Defect 146444 - owbackup/owrestore are using xprops
# which causes backups/restores to fail. TDP 10-Jan-03
#unset DISPLAY
#comment this unset DISPLAY for tar805604. if not comment this out, it does not work.
# Yan  28-Aug-2009

OSNAME=`uname`

print_help()
{
        echo "usage: $0 arguments"
        echo "arguments: (*) means mandatory"
        echo " <directory_name_to_store_TheOracleFile> (*)  set the directory to \
store the oracle backup file."      
        echo "  [ -OEXT]      <oracle_file_extension>  set extension for oracle backup file."
        echo "  [ -EXTFILEDIR] <directory_name_to_store_TheExternalFiles>  \
set the directory to store the project and seismic external backup files"
}

if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ] || [ "$1" = "help" ]
then
        print_help
        exit 1
fi


if [ "$1" = "" ]
then
        echo "$0: Error: missing <directory_name_to_store_TheOracleFile>"
        print_help
        exit 1
else
        if [ "${OSNAME}" = "Windows_NT" ]
        then
            print -r "Directory name to store the oracle backup file set to $1"
        else
            echo "Directory name to store the oracle backup file set to $1"
        fi
        oradirname=$1
        # for backward compatibility, handle the special case: <directory_name> <extension>
        if [ $# -eq 2 ]
        then            
            EXTENSION=$2
        fi      
fi

# set the default oracle file extension
if [ $# -eq 1 ]; then
   EXTENSION=.bck
fi

# in addition the exactly two arguments case, handle all other greater than two arguments cases
if [ $# -gt 2 ]
then
    shift  # move to the next flag
    while [ $# -gt 0 ]
    do
        temp=$1
        temp=`echo $temp | tr '[a-z]' '[A-Z]' `  # convert to upper case for the flag  
            
        case $temp in
            # if we want to support the extension name start with dash '-', then need more work here
            -OEXT)    if [ "$2" = "" ] || [ `echo $2|grep "^-" |wc -l` -gt 0 ]
                      then
                          echo "$0: Error: missing <oracle_file_extension>"
                          print_help
                          exit 1
                      else
                          echo "Oracle file extension set to \"$2\""                          
                          EXTENSION=$2
                          shift
                      fi
                      ;;
           -EXTFILEDIR) if [ "$2" = "" ] || [ `echo $2|grep "^-" |wc -l` -gt 0 ]
                      then
                          echo "$0: Error: missing <directory_name_to_store_ExternalFiles>"
                          print_help
                          exit 1
                      else
                          if [ "${OSNAME}" = "Windows_NT" ]
                          then
                                print -r "Directory name to store external files set to \"$2\""
                          else
                                echo "Directory name to store external files set to \"$2\""
                          fi
                          externaldir=$2
                          shift
                      fi
                      ;;
             *)
                      echo "unknown option flag: $1"
                      print_help
                      exit 1
                      ;;
        esac
        shift
    done
        
fi

# handle the case in which user does not specify the -OEXT oracle file extension
if [ "${EXTENSION}" = "" ]
then
    EXTENSION=.bck
fi

# If the input extension does not contain a '.', the add a '.' to the extension
echo $EXTENSION | egrep -s '\.'
if [ $? -ne 0 ]; then
     EXTENSION=.$EXTENSION
fi

DIRECTORY=$oradirname

# need to check and see if $DIRECTORY is a directory
if [ ! -d $DIRECTORY ]; then
  if [ "${OSNAME}" = "Windows_NT" ]
  then
        print -r "Input directory name $DIRECTORY is not valid."
  else
        echo "Input directory name $DIRECTORY is not valid."
  fi
  exit 1
else
  # add the file separator to the DIRECTORY name, it works both in Unix and Windows
      DIRECTORY=$DIRECTORY/  
fi

# check the directory to store external backup file
if [ -n "${externaldir}" ]; then
    if [ ! -d ${externaldir} ]; then
        if [ "${OSNAME}" = "Windows_NT" ]
        then
                print -r "Input directory name ${externaldir} is not valid."
        else
                echo "Input directory name ${externaldir} is not valid."
        fi
        exit 1
    else
     # add the file separator to the DIRECTORY name, it works both in Unix and Windows
       EXTDIRECTORY=${externaldir}/  
    fi
fi

FILEEXTENSION=".zip"

#
# Set up OS dependent environment for NT or unix.
#
. ${OWHOME}/bin/OwSysDep

#
# Set OW_BATCH_MODE
#
OW_BATCH_MODE="TRUE"
export OW_BATCH_MODE

#
# Set User's name and run directory based on which OS
#
if [ `uname -s` = "Windows_NT" -o `uname -s` = "Windows_95" -o `uname -s` = "Windows_98" ]; then
    USER="${USERNAME}"
    RUNDIR="${HOME}"
else
  if [ ! -d $HOME/run ]; then
    mkdir -p $HOME/run
    chmod 777 $HOME/run
  fi
  RUNDIR="${HOME}/run"
fi

#
# Which SID to backup
#
OWSYSSID=`lgc_getenv OWSYSSID`
if [ "${OWSYSSID:-""}" = "" ]; then
   echo "*** ERROR: OWSYSSID not set.  Correct and re-run."
   exit 1
fi

OS_SQLPLUS=sqlplus

#
# find list of projects that user is a manager of
#
SQLCMD="set feedback off
        set heading off
        set pagesize 0
        alter session set current_schema=owsys;
        select project_name from owsys.ow_sys_prj_user
          where user_id=upper('$USER') and security_level=3 minus
        select project_name from owsys.ow_sys_project
          where upper(project_type) = 'WORKING';"

PRJS=`echo "${SQLCMD}" | ${OS_SQLPLUS} -s ${owuser}/${owuserpwd}@${OWSYSSID} 2>${OS_NULLDIR}`


if [ "${PRJS:-""}" = "" ]; then
   exit 0
fi

echo "Backing up all of" $USER "'s Projects: " $PRJS " on SID =" $OWSYSSID
#
# Find a list of projects that user is not manager of
#
SQLCMD2="set feedback off
         set heading off
         set pagesize 0
         alter session set current_schema=owsys;
         select project_name from owsys.ow_sys_prj_user minus
         select project_name from owsys.ow_sys_prj_user
            where user_id=upper('$USER') and security_level=3 minus
         select project_name from owsys.ow_sys_project
            where upper(project_type) = 'WORKING';"

PRJS2=`echo "${SQLCMD2}" | ${OS_SQLPLUS} -s ${owuser}/${owuserpwd}@${OWSYSSID} 2>${OS_NULLDIR}`
#
   echo "========================================"
   echo ""
if [ "${PRJS2:-""}" = "" ]; then
   echo ""$USER" is capable of backing up all OpenWorks projects on instance "$OWSYSSID"."
else
   echo "UNABLE to backup the following projects as" $USER "on SID =" $OWSYSSID "."
   echo ""$USER" is not a manager of these projects:"
   echo $PRJS2
fi
   echo ""
   echo "========================================"
#

#
# For each project this user has privileges for, do backup
#

## need to combine the $1(directoryname) + projectName + extension as a backupfileName
## to pass into the OwBackup.java as a file name.

EXITNUM=0
PRJARY=""
for p in $PRJS
do
   APPLICATION="OwBatchBackupAll"
   echo "Backup project $p now..."
   if [ "${OSNAME}" = "Windows_NT" ]
   then
        print -r "Check $RUNDIR/owbackup-all_$p.err for log message..."
   else
        echo "Check $RUNDIR/owbackup-all_$p.err for log message..."
   fi
   #print -r "*** pass in the backup file name: $DIRECTORY$p$EXTENSION"
   if [ `uname -s` = "Windows_NT" -o `uname -s` = "Windows_95" -o `uname -s` = "Windows_98" ]; then
     # if the external file directory is set, then pass in the external file name
     # to the application and backup both oracle and external file for each project.
     if [ -n "${EXTDIRECTORY}" ]; then
        EXTERNALFILENAME="${EXTDIRECTORY}${p}_external${FILEEXTENSION}"
        SEISMICFILENAME="${EXTDIRECTORY}${p}_seismic${FILEEXTENSION}"
         echo "Application name: $APPLICATION"
         echo "Sid name: $OWSYSSID"
         echo "Project name: $p"
         if [ "${OSNAME}" = "Windows_NT" ]
         then
                print -r "Oracle backup file name: $DIRECTORY$p$EXTENSION"
                print -r "External backup file name: ${EXTERNALFILENAME}"
                print -r "Seismic backup file name: ${SEISMICFILENAME}"
         else
                echo "Oracle backup file name: $DIRECTORY$p$EXTENSION"
                echo "External backup file name: ${EXTERNALFILENAME}"
                echo "Seismic backup file name: ${SEISMICFILENAME}"
         fi
         
        $OWHOME/bin/OWRuntimeLauncher.bat "$APPLICATION" "$p" "$OWSYSSID" -oracle "$DIRECTORY$p$EXTENSION" -ow "${EXTERNALFILENAME}" -s "${SEISMICFILENAME}"
2>$RUNDIR/owbackup-all_$p.err 1>&2
     else     
        $OWHOME/bin/OWRuntimeLauncher.bat "$APPLICATION" "$p" "$OWSYSSID" -oracle "$DIRECTORY$p$EXTENSION" 2>$RUNDIR/owbackup-all_$p.err 1>&2
     fi
     EXITNUM=$?
   else     
     # if the external file directory is set, then pass in the external file name
     # to the application and backup both oracle and external file for each project.
     if [ -n "${EXTDIRECTORY}" ]; then
        EXTERNALFILENAME="${EXTDIRECTORY}${p}_external${FILEEXTENSION}"        
        SEISMICFILENAME="${EXTDIRECTORY}${p}_seismic${FILEEXTENSION}"
        echo "Application name: $APPLICATION"
        echo "Sid name: $OWSYSSID"
        echo "Project name: $p"
        if [ "${OSNAME}" = "Windows_NT" ]
        then
                print -r "Oracle backup file name: $DIRECTORY$p$EXTENSION"
                print -r "External backup file name: ${EXTERNALFILENAME}"
                print -r "Seismic backup file name: ${SEISMICFILENAME}"
        else
                echo "Oracle backup file name: $DIRECTORY$p$EXTENSION"
                echo "External backup file name: ${EXTERNALFILENAME}"
                echo "Seismic backup file name: ${SEISMICFILENAME}"
        fi
   
        $OWHOME/bin/OWRuntimeLauncher.sh "$APPLICATION" "$p" "$OWSYSSID" -oracle "$DIRECTORY$p$EXTENSION" -ow "${EXTERNALFILENAME}" -s "${SEISMICFILENAME}" 2
>$RUNDIR/owbackup-all_$p.err 1>&2
     
     else
        # only backup the oracle file.
        $OWHOME/bin/OWRuntimeLauncher.sh "$APPLICATION" "$p" "$OWSYSSID" -oracle "$DIRECTORY$p$EXTENSION"  2>$RUNDIR/owbackup-all_$p.err 1>&2
     fi
     EXITNUM=$?
   fi
   if [ "${EXITNUM}" != "0" ]; then
       PRJARY="$PRJARY $p\n"      
   else
    echo "$p: project backup finished"
   fi
done   
   if [ -n "${PRJARY}" ]; then
     echo ""
     echo "============== Backup the following project(s) failed ================"
     if [ `uname -s` = "Linux" ]; then
        echo -e $PRJARY
     else
        echo $PRJARY
     fi
   fi


论坛徽章:
0
发表于 2012-03-31 09:31 |显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP