- 论坛徽章:
- 0
|
先说下环境吧
主机名:orcle
系统:RHEL 6
软件:oracle 11G
在orcle上有个脚本,位于/tmp/backup.sh,执行这个脚本会对数据库进行expdp,导出的文件位于/tmp/data,并且会删除前一天导出来的dump文件,然后把最新导出的文件通过FTP上传到备份服务器上,以下是这个脚本的内容
[root@orcle data]# cat /tmp/backup.sh
#!/bin/sh
rq=`date +%y%m%d`
su - oracle -c "expdp prod/prod schemas=oracle dumpfile=expdp$rq.dmp logfile=expdp$rq.log DIRECTORY=/tmp/data"
find /tmp/data/ -name "expdp*" -mtime +0 -exec rm {} \;
ftp -n 10.10.10.110 <<EOF
user ftp 123456
bin
lcd /tmp/data
put expdp*
bye
EOF
我把这个脚本加入到/etc/crontab里,让系统每天20:00执行这个脚本
[root@orcle expdata]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
00 20 * * * root /tmp/backup.sh
下面就是遇到的问题
我用命令crontab -l 提示没有root用户的定时任务
[root@orcle data]# crontab -l
no crontab for root
而在/tmp/data下却有每天都生成的dmp文件,但是没有删除之前导出的文件(昨天18号晚上执行脚本,但没有自动删除17号导出的文件)
[root@orcle data]# cd /tmp/data/
[root@orcle data]# ls -nrt
total 512288
-rw-r--r-- 1 502 501 9143 Nov 17 13:26 export.log
-rw-r--r-- 1 502 501 9176 Nov 17 20:00 expdp121117.log
-rw-r----- 1 502 501 252485632 Nov 17 20:00 expdp121117.dmp
-rw-r--r-- 1 502 501 9176 Nov 18 20:00 expdp121118.log
-rw-r----- 1 502 501 272060416 Nov 18 20:00 expdp121118.dmp
我的问题:1,为何crontab -l 显示没有root用户的定时任务?是我在/etc/crontab里添加的那句语法错误?如果错误 又怎么会每晚20:00在/tmp/data都生成了导出的文件?
2,为何没有把之前导出的文件删掉,是我脚本的语法错误了吗?
|
|