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

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

问题描述

我在我的网络主机上创建了一个 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

你只需要转义百分号.

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

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

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