通过Cron将当前日期附加到文件名吗? [英] Append current date to the filename via Cron?

查看:72
本文介绍了通过Cron将当前日期附加到文件名吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Web主机上创建了一个Cron任务来每天备份我的数据库,并且希望将当前日期附加到文件名中。

I've created a Cron task at my webhost to daily backup my database and I would like it to append the current date to the filename.

我的Cron作业看起来像这样

My Cron job looks like this

mysqldump -u username -pPassword db_name > www/db_backup/db_backup+date%d%m%y.sql

但是我得到的文件是这个: db_backup + date 没有文件扩展名或日期。

But the file I get is this: db_backup+date no file extension or date.

我也尝试过此命令

mysqldump -u username -pPassword db_name > www/db_backup/db_backup_'date +%d%m%y'.sql 

但这不是甚至不提供文件输出。

but that doesn't even give an file output.

将日期附加到文件中的正确语法是什么?

What is the right syntax for getting the date appended to my file??

推荐答案

* * * * * echo "hello" > /tmp/helloFile_$(date +\%Y\%m\%d\%H\%M\%S).txt

您只需要转义括号即可。

You just need to escape the parentheses.

其他日期格式:
http://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/

这篇关于通过Cron将当前日期附加到文件名吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆