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.
–
–
–
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.
–
–
–
–
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.