Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Red Hat Enterprise Linux, Debian & Ubuntu
Posts: 92
Rep:
Using `date '+%Y%m%d'` in crontab?
Hey everyone,
I'm trying to figure out how to use cron to generate a file containing today's date, such as 'ls.log.20060105'.
I know Cron uses /bin/sh .
If I switch to /bin/sh , the command "ls foo bar > ls.log.`date +%Y%m%d` 2>&1" creates the file correctly. However, the file is NOT created when I put this same command in my crontab.
I've tried the following methods, and none of them create the file 'ls.log.20060105':
Code:
0 10 * * * ls foo bar > ls.log.`date +%Y%m%d` 2>&1
# Use a variable
0 10 * * * DATE=`date +%Y%m%d` ; ls foo bar > ls.log.$DATE 2>&1
# Use single quotes
0 10 * * * DATE=`date '+%Y%m%d'` ; ls foo bar > ls.log.$DATE 2>&1
# Escape the % characters with a \
0 10 * * * DATE=`date +\%Y\%m\%d` ; ls foo bar > ls.log.$DATE 2>&1
# Use single quotes AND escape the % characters with a \
0 10 * * * DATE=`date '+\%Y\%m\%d'` ; ls foo bar > ls.log.$DATE 2>&1
Also, I don't think variable expansion works well (if at all) in cronjobs. Rather than using $DATE, try (as you did in your test) just putting the expression there with the backticks.
Cron can be a beast sometimes. Most often when I need to do something of any complexity, I write a (small) script to do it and have cron just call that script for cleanliness.
You should probably open a new thread for your question.
Giving us just the DB-.... doesn't help. We'd need to see what the script is doing at least in the section where you have that and probably the entire script. There are tools in Linux to convert upper case to lower case but nothing does it automatically without you telling it to do so. Without seeing the whole script we can't tell what is doing this in your script.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.