我试图让一个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
发生这种情况是因为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)