当前位置: 技术问答>linux和unix
aix下crontab无法执行日志压缩命令,不定时执行却可以
来源: 互联网 发布时间:2017-05-22
本文导语: 写了个定时任务,先压缩日志,之后再删除原日志。 该语句 定时命令如下: 45 10 * * * tar cvf /weblog10/Applog/test-`date +%y%m%d`.tar /weblog10/test && rm -rf /weblog10/test 单独执行: tar cvf /weblog10/Applog/test-`date +%y%m%d`....
写了个定时任务,先压缩日志,之后再删除原日志。
该语句
定时命令如下:
45 10 * * * tar cvf /weblog10/Applog/test-`date +%y%m%d`.tar /weblog10/test && rm -rf /weblog10/test
单独执行: tar cvf /weblog10/Applog/test-`date +%y%m%d`.tar /weblog10/test && rm -rf /weblog10/test 可以正常执行。
但是设置crontab之后却无法执行。
打开了报错日志报如下错误,请各位帮指点下问题原因
Subject: Output from cron job tar cvf /weblog10/Applog/test-`date +, weblog10@Tzjapp, exit status 2
Cron Environment:
SHELL = /usr/bin/sh
PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java5/jre/bin:/usr/java5/bin
CRONDIR=/var/spool/cron/crontabs
ATDIR=/var/spool/cron/atjobs
LOGNAME=weblog10
HOME=/weblog10
Your "cron" job executed on Tzjapp on Thu Jul 3 10:35:00 GMT+08:00
tar cvf /weblog10/Applog/test-`date +
produced the following output:
tar: Jul: A file or directory in the path name does not exist.
tar: 3: A file or directory in the path name does not exist.
tar: 10:35:00: A file or directory in the path name does not exist.
tar: GMT+08:00: A file or directory in the path name does not exist.
tar: 2014: A file or directory in the path name does not exist.
*****************************************************************
cron: The previous message is the standard output
and standard error of one of the cron commands.
该语句
定时命令如下:
45 10 * * * tar cvf /weblog10/Applog/test-`date +%y%m%d`.tar /weblog10/test && rm -rf /weblog10/test
单独执行: tar cvf /weblog10/Applog/test-`date +%y%m%d`.tar /weblog10/test && rm -rf /weblog10/test 可以正常执行。
但是设置crontab之后却无法执行。
打开了报错日志报如下错误,请各位帮指点下问题原因
Subject: Output from cron job tar cvf /weblog10/Applog/test-`date +, weblog10@Tzjapp, exit status 2
Cron Environment:
SHELL = /usr/bin/sh
PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java5/jre/bin:/usr/java5/bin
CRONDIR=/var/spool/cron/crontabs
ATDIR=/var/spool/cron/atjobs
LOGNAME=weblog10
HOME=/weblog10
Your "cron" job executed on Tzjapp on Thu Jul 3 10:35:00 GMT+08:00
tar cvf /weblog10/Applog/test-`date +
produced the following output:
tar: Jul: A file or directory in the path name does not exist.
tar: 3: A file or directory in the path name does not exist.
tar: 10:35:00: A file or directory in the path name does not exist.
tar: GMT+08:00: A file or directory in the path name does not exist.
tar: 2014: A file or directory in the path name does not exist.
*****************************************************************
cron: The previous message is the standard output
and standard error of one of the cron commands.
|
百分号在crontab里面是特殊字符,需要转义:
45 10 * * * tar cvf /weblog10/Applog/test-`date +%y%m%d`.tar /weblog10/test && rm -rf /weblog10/test
45 10 * * * tar cvf /weblog10/Applog/test-`date +%y%m%d`.tar /weblog10/test && rm -rf /weblog10/test