Reputation: 105
I am trying to get a mono executable file to run automatically at a specific time each day, however it will not run from crontab.
Using crontab -e I have set the following scheduled task:
10 15 * * * (cd ~/Documents/automation && bash auto_run.sh)
Inside the auto_run.sh file I have the following:
#!/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
I have used chmod +x
on the files to make sure they execute.
At the scheduled time the date/time messages can be seen in the text file but the mono executable does not run. Running the file directly from the terminal with bash auto_run.sh
works perfectly.
Any help would be appreciated. I am using macOS Mojave
Upvotes: 1
Views: 343
Reputation: 3201
This is happening because mono
is not able to find the path where it should run from inside the cron.
Either you can put the path in .bash_profile
and source it while running the cron. Or run which mono
and mention the path inside script from where it is running the mono
command.
Command :
which mono
# It will give you path where mono
is present.
Script would be :
#!/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
Another way is, Put mono
path in .bash_profile
and run the cron like this :
10 15 * * * . ~/.bash_profile; (cd ~/Documents/automation && bash auto_run.sh)
Upvotes: 2