Solved

crontab job fail to append date as log file name

Posted on 2004-08-15
3
1,025 Views
Last Modified: 2013-12-27
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
Comment
Question by:damonchong
  • 3
3 Comments
 
LVL 38

Accepted Solution

by:
yuzh earned 250 total points
ID: 11807172
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
 
LVL 38

Expert Comment

by:yuzh
ID: 11807319
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
 
LVL 38

Expert Comment

by:yuzh
ID: 11807589
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now