【问题标题】:Running a cron job on ubuntu在 ubuntu 上运行 cron 作业
【发布时间】:2020-06-16 04:49:04
【问题描述】:

我有一个 python 脚本,它生成一个 csv 文件,然后使用 nodejs 脚本将 csv 文件转换为 xmls 文件,最后使用另一个 nodejs 脚本将 xmls 文件导入到谷歌电子表格中。

我希望能够运行一项每天自动执行一次的 cron 作业。

以下是我必须按顺序手动使用的命令列表:

 1- Cd to this project director Otomoto_project_final/otomoto_final_project/otomoto 
 2- Run a python script called otomoto.py ( this will generate an output.csv file )
 3- Cd back up .. to this path Otomoto_project_final/otomoto_final_project/
 4- Run the following command : node csvtoxmls.js ( this will generate the otomoto.xlsx file) 
 5 - Run the following command : node main.js ( this will push the otomoto.xlsx file to the google spread sheet )

【问题讨论】:

标签: linux ubuntu cron


【解决方案1】:

使用&&,您可以创建一个单行 cron 命令,该命令将按顺序执行命令(假设所有退出都没有错误)。 例如,如果您想在每天凌晨 3 点运行连续的命令,您可以添加到您的 crontab: 0 3 * * * python3 /full/path/to/first/script/otomoto.py && node /full/path/to/second/script/csvtoxmls.js && node /full/path/main.js

对于额外的 cron 配置,您可以查看:https://crontab.guru/

【讨论】:

    猜你喜欢
    • 2013-01-10
    • 2017-06-05
    • 2014-04-04
    • 2021-11-07
    • 2015-12-28
    • 2018-04-09
    • 2012-12-27
    • 2014-04-20
    • 1970-01-01
    相关资源
    最近更新 更多