Crontab Not Working with Bash on Ubuntu on Windows

arnpry picture arnpry · Dec 22, 2016 · Viewed 18.6k times · Source

I am trying to schedule a bash script to run with Bash on Ubuntu on Windows in Windows 10. Every time that I to write the cron, I get the following error messages in the terminal:

crontab: installing new crontab
/var/spool/cron/: mkstemp: Permission denied
crontab: edits left in /tmp/crontab.4q0z3i/crontab

Here is what the crontab entry looks like:

# m h  dom mon dow   command
27 10 * * * /home/admin/test.sh > /home/admin/logs/test.log 2>&1   

What exactly is going on here?

Answer

jeffpkamp picture jeffpkamp · Mar 15, 2017

You need to add yourself to the crontab group.

usermod -a -G crontab (username)

Once you have done this, you also need to make sure that cron is running. Usually this is started with start cron however upstart does not work on WSL from what I can tell, but sudo cron does the job.

One caveat to this is that once you close all bash windows, cron will stop running even though your computer runs. However, as long as you have a bash window open and cron running, it will perform as expected.