Thursday, April 15, 2010

Getting cron to play nice with me in cygwin

Our machines at work are currently running Win7, with cygwin. I've been a long time linux user, and have always enjoyed the composability of the command line tools.  I finally bit the bullet and decided to stop using Scheduled Tasks for a tool I'm more comfortable with: cron. Here is what it took to get all things working nice.

  • Install a MTA of your choice.  I did not want to deal with trying to setup qmail, sendmail or any other of the big tools for a machine that only needs to relay mail out.  I looked at nullmailer, ssmtp, and msmtp.  Ended up installing msmtp.  We use google apps for our mail needs, so I configured msmtp to work with it.  Here is my ~/.msmtprc config:

logfile ~/.msmtp.log

account gmail
port 587
auth on
user @
password *****
tls on
from @
tls_certcheck off

account default : gmail

  • Make sure that the MTA is working.  You might need to run msmtp-config to set things up, such as repointing /usr/sbin/sendmail to /usr/bin/msmtp.  As you can see, I turned off tls_certcheck.  I could not figure out, in the time I had, how to get certs into my machine.  Seems that openSSL doesn't install them anymore.  Might want to make sure that you "chmod 600" that config file to prevent your password from getting out.
  • Install cron.  As a user with right to intall services on your machine, run "cron-config".  That should take care of things.
  • Create a crontab.  Here is a very simple one I created.  It's nice to have it send me email with the output.  Read up on cron if you don't want that feature.  This file lives in: /var/cron/tabs/

# 0-59  0-23    1-31    1-12    0-6     cmd
# min   hour    DoM     mon     DoW     cmd

# silly test
 */5      *       *       *       *       date

That's all folks! Hope this helps someone out there.

No comments: