Running Mono from crontab

SneWs's picture

When I tried to get crontab to execute one of my mono compiled assemblies it failed with the error of not being able to resolve the assembly. The problem, after some investigation boiled down to the very simple fact of it not executing the script from the expected working directory. Easy enough to fix, just have crontab execute a cd into the working directory, and from there, execute with a relative path. Problem solved.

This is the shell script that I’m invoking from crontab:

mono --runtime=v4.0.30319 MonoDaemon.exe "/home/username/project/worker/logs"

And this was my initial crontab entry:

*/15 * * * * /home/username/project/worker/

And this is the way to get it to actually execute from the expected working folder:

*/15 * * * * ( cd /home/username/project/worker && ./ )

Notice the parenthesizes and the &&, this allows cron to first switch directory followed by executing the script. Problem solved!

So if you ever have problem scheduling a Mono executable from crontab, check your expected working folder to allow the mono runtime to be able to resolve your assemblies properly.


by Alan Peterson on Thu, 06/05/2014 - 18:22

Hmm linux is a wonderful and secure server for the running online services. I have been using this OS for so many years when i was running a dns on my system for my isp firm.

by Martin on Wed, 02/04/2015 - 09:46

Hey Marcus!
It works perfectly, thank you!

Post new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
© 2008 - 2017 Marcus Grenängen. Drupal theme by Kiwi Themes.