bash - Mono 可执行文件不会从 Mac 上的 crontab 运行
问题描述
我试图让一个单声道可执行文件在每天的特定时间自动运行,但它不会从 crontab 运行。
使用 crontab -e 我设置了以下计划任务:
10 15 * * * (cd ~/Documents/automation && bash auto_run.sh)
在 auto_run.sh 文件中,我有以下内容:
#!/bin/bash
echo “`date “+%Y-%m-%d %H:%M:%S”` : auto run starting >> auto_run_logging.txt
mono /Users/admin/Projects/auto_task/auto_task/bin/Debug/auto_task.exe
echo “`date “+%Y-%m-%d %H:%M:%S”` : auto run ending >> auto_run_logging.txt
我已chmod +x
在文件上使用以确保它们执行。
在预定时间,可以在文本文件中看到日期/时间消息,但单声道可执行文件不运行。直接从终端运行文件bash auto_run.sh
效果很好。
任何帮助,将不胜感激。我正在使用 macOS Mojave
解决方案
发生这种情况是因为mono
无法找到它应该从 cron 内部运行的路径。
.bash_profile
您可以在运行 cron 时将路径放入并获取它。或者运行which mono
并提及脚本中运行mono
命令的路径。
命令 :
which mono
# 它会为你mono
提供存在的路径。
脚本将是:
#!/bin/bash
echo “`date “+%Y-%m-%d %H:%M:%S”` : auto run starting >> auto_run_logging.txt
/path/to/mono/mono /Users/admin/Projects/auto_task/auto_task/bin/Debug/auto_task.exe
echo “`date “+%Y-%m-%d %H:%M:%S”` : auto run ending >> auto_run_logging.txt
另一种方法是,将mono
路径放入.bash_profile
并像这样运行 cron:
10 15 * * * . ~/.bash_profile; (cd ~/Documents/automation && bash auto_run.sh)
推荐阅读
- typescript - 如何从给定的字符串导入打字稿文件?
- java - 通过 prometheus 支持多个指标(statsd 和 prometheus)
- html - 波纹CSS不显示
- python - 在 PyQT5 的 groupbox 中显示 matplotlib 图表
- c++ - 有没有办法在 C++ 中调用没有 () 的函数?
- python-3.x - 如何保证我的异步倒计时功能实时运行?
- reactjs - 收到一个 TypeError: Cannot read property 'map' of undefined in React
- python - Pandas 列表的列,检查列表是否相交
- javascript - 更改事件的多边形选项。谷歌地图
- javascript - CSS 3D 动画车轮偏离中心