?
Solved

crontab job fail to append date as log file name

Posted on 2004-08-15
3
Medium Priority
?
1,039 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

770 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