[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

crontab job fail to append date as log file name

Posted on 2004-08-15
3
Medium Priority
?
1,040 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 38

Accepted Solution

by:
yuzh earned 750 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

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
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 how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

656 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