首页 > 解决方案 > 在 ubuntu 上运行 cron 作业

问题描述

我有一个 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 )

标签: linuxubuntucron

解决方案


使用&&您可以创建一个单行 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/


推荐阅读