• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1042
  • Last Modified:

crontab job fail to append date as log file name

Hi,
I have the following entry in my crontab list.

16 17 * * * /usr/bin/ksh -c ". /usr/home/user/.profile ; /disk1/servers/rel/scripts/HouseKeep  > /disk1/servers/rel/log/Backup/housekeep.log.`date +%Y%m%d.%H:%M:%S`"

However the file generated is only housekeep.log.
the date part is missing.

However when I manulaly execute the following then the date part is generated.
1)/disk1/servers/rel/scripts/HouseKeep  > /disk1/servers/rel/log/Backup/housekeep.log.`date +%Y%m%d.%H:%M:%S`"

2)/usr/bin/ksh -c ". /usr/home/user/.profile ; /disk1/servers/rel/scripts/HouseKeep  > /disk1/servers/rel/log/Backup/housekeep.log.`date +%Y%m%d.%H:%M:%S`"

Many thanks in advance !!


0
damonchong
Asked:
damonchong
  • 3
1 Solution
 
yuzhCommented:
The prolem is the  "%" is special to cron  and and must be escaped.

change your cron entry to:

16 17 * * * /usr/bin/ksh -c ". /usr/home/user/.profile ; /disk1/servers/rel/scripts/HouseKeep  > /disk1/servers/rel/log/Backup/housekeep.log.`date +\%Y\%m\%d.\%H:\%M:\%S`"


should work.

man crontab
to learn more details
0
 
yuzhCommented:
It is better to redirect stderr to the log file as well:

16 17 * * * /usr/bin/ksh -c ". /usr/home/user/.profile ; /disk1/servers/rel/scripts/HouseKeep  > /disk1/servers/rel/log/Backup/housekeep.log.`date +\%Y\%m\%d.\%H:\%M:\%S` 2>&1"

0
 
yuzhCommented:
Hi damonchong,

   Why a B grade? please read the following page to learn how to grade at EE:
   http://www.experts-exchange.com/help.jsp#hi73
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now