Mono可执行文件将无法在Mac上的crontab中运行

问题描述 投票:0回答:1

我试图让一个Mono可执行文件在每天的特定时间自动运行,但是不会从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以确保它们执行。

在计划的时间,日期/时间消息可以在文本文件中看到,但是mono可执行文件无法运行。直接使用bash auto_run.sh从终端运行文件非常有效。

任何帮助将不胜感激。我正在使用macOS Mojave

bash macos cron mono
1个回答
0
投票

发生这种情况是因为mono无法从cron内部找到它应该运行的路径。

您都可以在运行cron的同时将路径放入.bash_profile并提供源代码。或运行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)
© www.soinside.com 2019 - 2024. All rights reserved.