Cron reads the configuration files for a list of commands to execute. The daemon uses a specific syntax to interpret the lines in the crontab configuration tables. To be able to set up a cron job, we need to understand the basic elements that make up this syntax. quote=XerraX @ Jun 25 2009, 12:17 PMTo setup a Windows machine to run cron.php at a specific time follow the specific instructions below. This can be useful if you are not familiar with Linux/Unix, or if your web host does not offer the ability to run cron jobs; you can run them remotely from your own computer. Automating Server Scripts with Cron. Cron is a software utility which uses a time-based job scheduler in Linux operating systems. You can use cron to schedule jobs to run at fixed times, dates, or intervals. CRONw is a small collection of Perlie things providing the main functions of a.nix-style CRON to the Perl-enabled Windows world. The killer feature and the reason I built it: It runs as a system service without any additional tools, using the functionality provided by Win32::Daemon. Microsoft Windows’ counterpart for cron is the Scheduled Task. Each Scheduled Task is planned by the Task Scheduler. This application has been available since Windows NT 4.0, known as Task Scheduler 1.0. On modern Windows systems (Windows Server 2016, 2019, Windows 10 etc.), the Task Scheduler is available in version 2.0.
Update (12/30/2019): This was originally written on 09/25/2018 and was for WSL 1.At the time of writing this line, the setup for my WSL 1 still works (with win10 1909).
This is a short tutorial about how to use WSL(Windows Subsystem for Linux) to schedule cron jobs,with a specific example of backing up Evernote’s database, to show how versatile this method isand potential benefits. In this example, the strategy is optimized for large files that have frequentsmall changes regarding I/O writes.
It was the second time for me to lose a note in Evernote.The first one was due to a sync error. It was nothing serious but unnerving.But I lost the second one merely after I locked my phone whilebeing prompted to type the password for some encrypted text in that note.And the problem is, I have almost no direct way to know if a note is missingconsidering the size of my Evernote database.
So, after searching around, I decided that, since Evernote isstill the best app for my note taking (it has unlimited cloud storage,support for most platforms, bots for different apps etc.) andthere is no 100% secure data storage in this world, I need tobackup the database file on my own.
Side note: I saw a lot of discussion about switching applications to have more secure database.Unfortunately, that is not the case. Evernote is mature enough that the official client gives usersthe option to backup the database directly and access with ease later on.To prevent data loss, the ultimate solution is to have multiple backups.
Why rsync and WSL
It is tedious to manually copy and paste the database files to otherlocations (and track the version history). Storing the db directly insidethe local cloud storage sync folder is also not feasible for me since those applicationsneed to scan my 3.14 GB .exb file each time when I make any tiny changes to my notes.
I need a scheduled job with minimum disk usage (reading and writing).The reading part is hard to get rid of. So the focus is I/O write usage.I need a binary incremental backup.
rsync is the best candidateI know so far but it does not have native support for Windows.
Since I need my cloud storage application to run in the background all the time, itis not viable for me to schedule that application to sync. The workaround is touse scheduled
rsync to copy the .exb file to the local sync folder.
rsync is able to do binary incremental copy, keeping the write usage at minimum.And the sync application only reads the local file as scheduled(my specific application, Dropbox, can binary incremental sync, too). Unless there isa way to directly binary incremental copy to the cloud as scheduled while theother parts are not affected, this solution only needs 2 full scans and verylittle write + upload to work.
rclone but it does not support binary incremental upload)
About the Database File
There is an official guide for it.It explains how to find the location, how to export the note from a database file and so on.
If not installed yet, install cloud storage sync clients, WSL for Windows,
rsync based on the Linux distro installed.
To learn more about cron, use
man cron and
man crontab or search online.
Please at least read the
rsync --help and decide which options are preferred.The following command is the one I am using.
-n flag enables dry-run. Remove it after everything is confirmedto be correct by running this command directly (and see the result).
Create crontab Job
Crontab Windows Server
Log in as the user you want to run the job (note the privileges) and edit their crontab:
Using the editor chosen, add this line:
This is my config. It will run the command every 2 days at 22:22 (10:22 pm) and thus backup my Evernote database every 2 days.
If you want to learn more about crontab job, feel free to search on your own.
If you want, you can use the snapshot feature of rsync. But since Dropbox has pretty good version history, I did not include that.
(Since a note might be found missing after a long time, I highly recommendmanually adding backups for longer period, Like a full backup for each half year using another cron job)
Make the Daemon start at Windows Boot
The last step is to make sure the cron daemon runs in background when Windows boots.It can be achieved by making bash.exe/wsl.exe a service and so on.
The solution I chose was to create a shortcut containing a start command in the
shell:startup folder.Feel free to have your own choices and search around.
First, make sure the start command can be run without root privilege, unless you want totype in your sudo password every time you boot Windows.
Open sudo config file: Greatest r and b hits download.
Add the following line:
Save and quit and fix any problem if prompted.
shell:startup in the Run and explorer will open the startup folder.
Create a shortcut to wsl.exe and edit the properties as following:
And it should work unless the developers change how wsl works in the future.
Check If cron Service Started Properly
If you are worrying about cron service, here is a way to test it.
Create a test job in crontab. For example:
It will append “test” to a file in that path for every hour at 35.
First wait for the job to run first time and check the file to see result.
Now manually terminate the cron service and reboot Windows to see if it works.
After reboot, check task manager to see if there is a process called
Wait for the to run second time and check the result.
The command above is only an example. You can change it however you like.
Until now, it should be clear that what I did is only a little trick.But it shows how Unix commands can make Windows easier to use with WSL.
- man page of each command
- 11/16/2018: changed the original title and added abstract summary
How to View Jobs in Crontab
crontab -u username -lExample with user testuser:
crontab -u testuser -l
View Daily Cron JobsView all the daily cron jobs:
ls -la /etc/cron.daily/View a specific daily cron job:
less /etc/cron.daily/filenameExample with file name logrotate:
View Hourly Cron JobsFirst view all the hourly cron jobs:
ls -la /etc/cron.hourly/Then view a specific hourly cron job:
less /etc/cron.hourly/filenameExample with file name 0anacron:
View Weekly Cron JobsFirst view all the weekly cron jobs:
ls -la /etc/cron.weekly/Then view a specific weekly cron job:
less /etc/cron.weekly/filenameExample with file name weeklyexample:
View Monthly Cron JobsFirst view all the monthly cron jobs:
ls -la /etc/cron.monthly/Then view a specific monthly cron job:
less /etc/cron.monthly/filenameExample with file name readahead-monthly.cron:
less /etc/crontabExample Result: When a standard Cloud VPS is not enough, Liquid Web’s HIPAA compliant web hosting using our Dedicated Servers are a dream come true. Liquid Web’s server outmatches the competition on performance and support. Check out how our Dedicated Servers can skyrocket your site’s performance.