Chinaunix首页 | 论坛 | 博客
  • 博客访问: 651200
  • 博文数量: 168
  • 博客积分: 2928
  • 博客等级: 中校
  • 技术积分: 1904
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-04 09:56
文章分类

全部博文(168)

文章存档

2010年(168)

我的朋友

分类: Oracle

2010-04-15 09:14:01

今天遇到一个问题 crontab里面的任务怎么也不执行,手工执行就没有问题,就是自动调度的时候不执行,后来才知道犯了一个超级傻缺的错误:

1. 新增crontab中的任务
  crontab -e
   "/var/tmp/aaa002939" 7 lines, 496 characters 
   0      10       *       *       *       /expdata/rpt/scripts/create_snapshot.sh>/dev/null 2>&1
   "/var/tmp/aaa002939" 7 lines, 497 characters
   warning: commands will be executed using /usr/bin/sh

2. 到10点中的时候,任务没有执行,手工执行多次,确认没有问题

3. 查看.sh和.sql的权限问题,确认也没有问题

4. 到crontab 是不会根据用户自动搜索环境变量的,man的信息如下:
   Users who desire to have their .profile executed must explicitly do so
   in the crontab entry or in a script. called by the entry.

5. 在.sh脚本中加入export 环境变量
   原始脚本:
  more /expdata/rpt/scripts/create_snapshot.sh
   sqlplus
   @/expdata/rpt/scripts/create_snapshot.sql
  
  
more /expdata/rpt/scripts/create_snapshot.sql
   exec dbms_workload_repository.create_snapshot();
   exit;

  
   更新后脚本
  vi create_snapshot.sh
   "create_snapshot.sh" 1 line, 70 characters
   export ORACLE_BASE=/oracle
   export ORACLE_HOME=$ORACLE_BASE/product/10.2/db
   export ORACLE_SID=bidb
   export PATH=/usr/bin:/etc/:/usr/sbin:/usr/ucb:/usr/local/bin:$ORACLE_HOME/bin:/usr/bin/X11:/sbin:$PATH
   export NLS_LANG=american_america.ZHS16GBK
  
   sqlplus
   @/expdata/rpt/scripts/create_snapshot.sql

6. man crontab
  man crontab 
  
    crontab(1)                                                       crontab(1)
  
    NAME
         crontab - user job file scheduler
  
    SYNOPSIS
         crontab [file]
  
         crontab -e [username]
  
         crontab -l [username]
  
         crontab -r [username]
  
    DESCRIPTION
         The crontab command manages a crontab file for the user.  You can use
         a crontab file to schedule jobs that are executed automatically by
         cron (see cron(1M)) on a regular basis.  The command has four forms:
  
              crontab [file]         Create or replace your crontab file by
                                     copying the specified file, or standard
                                     input if file is omitted or - is specified
                                     as file, into the crontab directory,
                                     /var/spool/cron/crontabs.  The name of
                                     your crontab file in the crontab directory
                                     is the same as your effective user name.
                                     If the compartmentalization feature is
                                     enabled, the crontab file is your
                                     effective user name followed by a colon
                                     (:), followed by the compartment id from
                                     which the crontab file is created.
  
              crontab -e [username]  Edit a copy of the user's crontab file, or
                                     create an empty file to edit if the
                                     crontab file does not exist.  When editing
                                     is complete, the file will be copied into
                                     the crontab directory as the user's
                                     crontab file.  If the compartmentalization
                                     feature is enabled, it only edits a copy
                                     of the user's crontab file from the
                                     compartment that the crontab files were
                                     created from.
  
              crontab -l [username]  Lists the user's crontab file.  If the
                                     compartmentalization feature is enabled,
                                     it only lists the crontab files from the
                                     compartment that the crontab files were
                                     created from.
  
              crontab -r [username]  Remove the user's crontab file from the
                                     crontab directory.  If the
                                     compartmentalization feature is enabled,
                                     it only removes the crontab files from the
  
    Hewlett-Packard Company            - 1 -       HP-UX 11i Version 3 Feb 2007
  
    crontab(1)                                                       crontab(1)
  
                                     compartment that the crontab files were
                                     created from.
  
         Only a privileged user can use username following the -e, -l, or -r
         options, to edit, list, or remove the crontab file of the specified
         user.
  
         The entries in a crontab file are lines of six fields each.  The
         fields are separated by spaces or tabs.  The lines have the following
         format:
  
              minute  hour  monthday  month  weekday  command
  
         The first five are integer patterns that specify when the sixth field,
         command, should be executed.  They can have the following ranges of
         values:
  
              minute         The minute of the hour, 0-59
  
              hour           The hour of the day, 0-23
  
              monthday       The day of the month, 1-31
  
              month          The month of the year, 1-12
  
              weekday        The day of the week, 0-6, 0=Sunday
  
         Each pattern can be either an asterisk (*), meaning all legal values,
         or a list of elements separated by commas.  An element is either a
         number in the ranges shown above, or two numbers in the range
         separated by a hyphen (meaning an inclusive range).  Note that the
         specification of days can be made in two fields: monthday and weekday.
         If both are specified in an entry, they are cumulative.  For example,
  
              0   0   1,15   *   1   command
  
         runs command at midnight on the first and fifteenth of each month, as
         well as every Monday.  To specify days in only one field, set the
         other field to asterisk (*).  For example,
  
              0   0   *   *   1   command
  
         runs command only on Mondays.
  
         The sixth field, command (the balance of a line including blanks in a
         crontab file), is a string that is executed by the shell at the
         specified times.  A percent character (%) in this field (unless
         escaped by a backslash (\)) is translated to a newline character,
         dividing the field into "lines".  Only the first "line" (up to a % or
         end-of-line) of the command field is executed by the shell.  Any other
         "lines" are made available to the command as standard input.
  
    Hewlett-Packard Company            - 2 -       HP-UX 11i Version 3 Feb 2007
  
    crontab(1)                                                       crontab(1)
  
         Blank lines and those whose first non-blank character is # will be
         ignored.
  
         cron invokes the command from the user's HOME directory with the POSIX
         shell, (/usr/bin/sh).  It runs in the c queue (see queuedefs(4)).
  
         cron supplies a default environment for every shell, defining:
  
              HOME=user's-home-directory
              LOGNAME=user's-login-id
              PATH=/usr/bin:/usr/sbin:.
              SHELL=/usr/bin/sh
  
        Users who desire to have their .profile executed must explicitly do so
         in the crontab entry or in a script. called by the entry.
  
         You can execute crontab if your name appears in the file
         /usr/lib/cron/cron.allow.  If that file does not exist, you can use
         crontab if your name does not appear in the file
         /usr/lib/cron/cron.deny.  If only cron.deny exists and is empty, all
         users can use crontab.  If neither file exists, only the root user can
         use crontab.  The allow/deny files consist of one user name per line.
  
       Security Restrictions
         If the compartmentalization feature is enabled, cron and crontab
         invoke the jobs from the compartment that the jobs were created from.
         Note that crontab creates the job files in /var/spool/cron/crontabs.
         Hence, if the crontab command is invoked from a compartment which has
         no write access to this directory and which disallows the COMMALLOWED
         privilege, crontab fails to schedule the jobs.  See compartments(5)
         and privileges(5) for more information.
  
    EXTERNAL INFLUENCES
       Environment Variables
         LC_CTYPE determines the interpretation of text within file as single
         and/or multibyte characters.
  
         LC_MESSAGES determines the language in which messages are displayed.
  
         If LC_CTYPE or LC_MESSAGES is not specified in the environment or is
         set to the empty string, the value of LANG is used as a default for
         each unspecified or empty variable.  If LANG is not specified or is
         set to the empty string, a default of "C" (see lang(5)) is used
         instead of LANG.
  
         If any internationalization variable contains an invalid setting,
         crontab behaves as if all internationalization variables are set to
         "C".  See environ(5).  EDITOR determines the editor to be invoked when
         -e option is specified.  The default editor is vi.
  
    Hewlett-Packard Company            - 3 -       HP-UX 11i Version 3 Feb 2007
  
    crontab(1)                                                       crontab(1)
  
       International Code Set Support
         Single-byte and multibyte character code sets are supported.
  
    WARNINGS
         Be sure to redirect the standard output and standard error from
         commands.  If this is not done, any generated standard output or
         standard error is mailed to the user.
  
    FILES
         /var/adm/cron                 Main cron directory
         /var/adm/cron/cron.allow      List of allowed users
         /var/adm/cron/cron.deny       List of denied users
         /var/adm/cron/log             Accounting information
         /var/spool/cron/crontabs      Directory containing the crontab files
  
    SEE ALSO
         sh(1), cron(1M), queuedefs(4), compartments(5), privileges(5).
  
    STANDARDS CONFORMANCE
         crontab: SVID2, SVID3, XPG2, XPG3, XPG4
  
    Hewlett-Packard Company            - 4 -       HP-UX 11i Version 3 Feb 2007

参考文献:http://blog.sina.com.cn/s/blog_540da1f60100dwd3.html

阅读(5195) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~