Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I set up some cronjobs a while back using crontab -e . My crontab includes the following line:

* * * * * /usr/bin/touch /home/blah/MADEBYCRON

It's been weeks since I did this. I have never seen /home/blah/MADEBYCRON. I set permissions on my home directory so it should be able to create files in this directory, so why does this file never exist?

/var/log/syslog does not exist.

Running cron on WSL seems to require some crazy hacks. There is no indication in your question that you have any such hacks in place. The least wacky I saw from quick google results amounted to turning WSL into a Windows service. (Not particularly precise I'm afraid; my recommended solution is always to ditch Windows.) – tripleee Feb 17, 2020 at 7:59 Did you manage to get this to work? I have an exact similar problem; I start atd and cron both manually on every restart, but the cron jobs never execute. In my case I noticed when I was upgrading some packages, the cron started working. However on next reboot it was back to the same situation. – Ali Awais Mar 9, 2020 at 18:41 Hi, I found this scottiestech.info/2018/08/07/… but its a kinda hacking and requires very very big effort .. :/ – xxxvodnikxxx Jul 25, 2020 at 12:19

Ensure that the cron service is running. I use WSL with cron every day for my local backups using rsync so this should work.

Use which cron to check its installed, mine says /usr/sbin/cron.

Use crontab -l to list your configured jobs.

Use ps aux | grep cron to look see if cron is running, you should see /usr/sbin/cron if it is.

Use service cron status to check if the service is started.

Use sudo service cron start to start the cron service if it is not running.

so after running the start command there is still no cron process nor does the status check say anything useful. – Damo Feb 18, 2020 at 8:06 @Damo That worked for me, but now it doesn't log anything. The file /var/log/cron.log is empty file) and /var/log/syslog has no entries about cron. – Dwhitz Jan 12, 2022 at 14:01 I solved the log issue updating the conf /etc/rsyslog.d/50-default.conf, see serverfault.com/a/470938/321667 and then restarting rsyslog sudo service rsyslog restart – Dwhitz Jan 12, 2022 at 14:16 Use ps aux | grep cron to look see if cron is running. And if it isn't running, then go to stackoverflow.com/questions/41281112/…. This worked for me with Pengwin (Ubuntu based) in WSL 2. – Stephen Hosking Mar 6, 2022 at 23:30

Since WSL is not starting services on startup you also need to start rsyslog before starting cron if you want to see the cron logs in /var/log/syslog:

sudo service rsyslog start
sudo service cron start

Then view logs

grep -i cron /var/log/syslog

syslog only has the information which script was run and when. If you want to see the output of the script you need to redirect it to a file, e.g. like this:

* * * * * /usr/bin/touch /home/blah/MADEBYCRON >> /home/blah/cron_output.log 2>&1

Under recent WSL releases, you can enable Systemd support as mentioned in this Community Wiki answer. With Systemd, the cron service (unit) should automatically be started when you start your WSL distribution.

Note that Systemd is not required under WSL, and may add additional, unneeded overhead. Consider using one of the other existing answers if you don't need Systemd support.

You need to start the cron service. Services do note start automaticaly on WSL as ist does not use systemd. The easyest way to do this is to add the following line to your .bashrc:

service cron status || sudo service cron start

On the first start you will need to enter the sudo password and you will see somthing like this

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.