linux - 在 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 )
解决方案
使用&&
您可以创建一个单行 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/
推荐阅读
- javascript - 用JS传递一个对象在节点中抛出新的错误
- sql - ROLLUP 函数的不同别名
- java - 带有字符串键和值集的映射
- c++ - c++ std::thread从对象原因调用方法调用这个类的析构函数
- python - 试图向 mySQL 数据库插入一个值
- c++ - 为什么我的代码在添加不相关的代码行后工作方式不同?
- vba - 使用多个 SUB 更好还是将所有代码放在一个 SUB 中更好
- r-markdown - 选项 results = 'asis' 在 xaringan 演示文稿中是否有效?
- c++ - 为什么 Unix IPC 解决方案在自定义基准测试中会失去超过 16 MiB 的吞吐量性能?
- python - 将第 N 维中的项目拆分和交换到第 N+1 维