为cronjob自动设置文件的名称

发布于 2025-01-26 09:14:36 字数 373 浏览 2 评论 0原文

我拥有以下我设置的Cronjob,可以通过Putty运行Python脚本。该脚本下载一些数据,将其导入到CSV(作为参数给出的文件)并将其推向我的GitHub:

0 16 * * * python3 UnderdogADP.py ud_adp_05022022.csv && git add ud_adp_05022022.csv && git commit -m "Updated ADP" && git push >> adp.log

有没有办法根据日期动态更改文件名更改?例如,我希望今天的文件名是UD_ADP_05032022.CSV,明天有UD_ADP_05042022.CSV等吗?感谢您的帮助!

I have the following cronjob that I have set up to run a Python script through PuTTY. The script downloads some data, imports it to a csv (the file that is given as an argument) and pushes it to my Github:

0 16 * * * python3 UnderdogADP.py ud_adp_05022022.csv && git add ud_adp_05022022.csv && git commit -m "Updated ADP" && git push >> adp.log

Is there a way to have the filename change dynamically based on the date? For example, I would want the filename today to be ud_adp_05032022.csv and tomorrow have it be ud_adp_05042022.csv, etc.? Thanks for the help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

殊姿 2025-02-02 09:14:36

我能够使用此语法来解决它:

0 16 * * * python3 UnderdogADP.py ud_adp_`date +%m%d%Y`.csv && git add ud_adp_`date +%m%d%Y`.csv && git commit -m "Updated ADP" && git push >> adp.log

I was able to fix it with this syntax:

0 16 * * * python3 UnderdogADP.py ud_adp_`date +%m%d%Y`.csv && git add ud_adp_`date +%m%d%Y`.csv && git commit -m "Updated ADP" && git push >> adp.log
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文