1. 新增crontab中的任务
oracle@BI-DB-HIS:/expdata/rpt/scripts$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. google到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 环境变量
原始脚本:
oracle@BI-DB-HIS:/expdata/rpt/scripts$more /expdata/rpt/scripts/create_snapshot.sh
sqlplusleiz/mleiz@bidb @/expdata/rpt/scripts/create_snapshot.sql
oracle@BI-DB-HIS:/expdata/rpt/scripts$more /expdata/rpt/scripts/create_snapshot.sql
exec dbms_workload_repository.create_snapshot();
exit;
更新后脚本
oracle@BI-DB-HIS:/expdata/rpt/scripts$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
sqlplusleiz/mleiz@bidb @/expdata/rpt/scripts/create_snapshot.sql
6. man crontab
oracle@BI-DB-HIS:/expdata/rpt/scripts$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
1 执行 crontab -e 2 在vi中编辑 48 10 5 8 * echo "hello world" 3保存 系统就会自动执行了,会把执行结果发到你的mail 里面(/usr/spool/mail/用户名) ******* 当程序在你所指定的时间执行后,系统会寄一封信给你,显示该程序执行的内容,
先打开crontab的日志看一下 参考 打开crontab的日志记录
或者重定向crontab的到特定的文件,再进行参考,才能确定错误。 参考定时任务不执行的解决方法
还有一点需要确认,请将你的定时任务配置发出来,也有很大可能是因为配置写错造成无法运行