Solved

crontab job fail to append date as log file name

Posted on 2004-08-15
3
1,037 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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…
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.

730 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