Remote › Cron jobs
PremiumThe Remote cron jobs page runs commands and scripts on your servers on a schedule. You decide whether WebDonkey starts a job over SSH or the server starts it itself from its crontab. The crontab is the list of scheduled commands that the cron service on the server works through. WebDonkey only touches the lines in it that it wrote itself. Remote cron jobs are a Premium feature.
What you do here
- Create a cron job: server, command or script file, schedule.
- Who runs the job: WebDonkey over SSH or the server's crontab, and how to switch between them.
- Manage jobs: run now, pause, read the log, see the other lines of the crontab.
Page layout
- Header: title and short description, on the right New remote cron job. Without an SSH connection the button is locked; add one under Connections first.
- Risk notice: the strip Caution: working directly on the server, as on every Remote page.
- Connections (left): your servers with search and folders, each with its number of jobs. Pick a server and the page shows only its jobs, and a new job starts with that server.
- One section per server: name and
user@host, below them the cards of its jobs and at the end Other lines in this crontab (not from WebDonkey, read-only). - A job's card: name, schedule (such as "every 5 minutes"), who starts it (started by WebDonkey or runs on the server), marks such as paused, in crontab and exit 0, then the command, Last run and, for WebDonkey jobs, Next run. On the right Run now, the pause switch, edit (pencil) and delete (bin). At the bottom, Log unfolds the latest output.
When you open the page, WebDonkey looks into the crontab of the server picked and of every server with jobs. WebDonkey lines that are already there, from another Mac for example, show up by themselves as jobs the server runs.
Without any job the page says No remote cron jobs yet. with a button to create one.
Free and Premium
Creating, editing, running and resuming need Premium. When Premium ends, your jobs stay visible, because jobs in the crontab keep running on the server. The page then shows a plain list with a note that Premium has ended. Each job has Pause (takes its line off the server) and Delete (removes the job completely). Jobs WebDonkey starts are on hold without Premium. Without any jobs a lock lies over the page. Prices are at webdonkey.io/pricing.
From the command line
wd remote cron lists the jobs, wd remote cron run runs one now. With add, edit and delete you create, change and delete. More under Servers (Remote).
Create a cron job Premium
A remote cron job runs a command or a script file on a server on a schedule, such as a shop's task runner every five minutes. Each run writes its output and exit code into a log on the server that you read in WebDonkey.
Where to find it
Sidebar Remote › Cron jobs, then New remote cron job at the top right. You open an existing job with the pencil on its card; the dialog is then called Edit remote cron job.
How to do it
- Pick the server on the left and click New remote cron job.
- Check the Server and enter a Name, such as "Clear shop cache".
- Under What runs, choose Command and type the line, or Script file and pick the file with Browse….
- Under How it runs, choose who starts the job. Triggered by WebDonkey is a good start, see Who runs the job.
- Choose the Schedule, such as Every 5 minutes. The expression it becomes is shown below.
- Leave Active ticked.
- Click Save. For a job on the server the button shows Writing crontab… until the line is in.
- Test the job with Run now on its card and look at the Log.
Save unlocks once there are a server, a name, a command or a script file and a valid schedule.
Fields and options
| Field | Meaning |
|---|---|
| Server | The SSH connection. The server picked on the left is preselected. When editing, it can no longer be changed. |
| Name | What the job is called in WebDonkey. For a job in the crontab it also stands after the marker there, so another Mac recognises the job by that name. |
| What runs › Command | A single line that sh runs in your home directory on the server. Output and exit code go to the log. Chain several commands as in the shell, with && for example. |
| What runs › Script file | A file on the server. Browse… opens Choose the script. The file runs with the interpreter of its #! line. Without one, .php runs with php, .sh with sh and .py with python3. WebDonkey looks up the interpreter's full path on the server when you save. |
| How it runs | Triggered by WebDonkey (default for new jobs) or Run on the server. |
| Schedule | Every minute, Every 5 minutes, Every 15 minutes, Hourly, Daily (with a time), Weekly (with weekday and time) or Cron expression with your own expression. The default is daily at 03:00. |
| Active | Only an active job runs. In server mode the field reads Active (line is in the crontab). |
Below the schedule it says which local time applies and the expression it becomes, such as "Times are this Mac’s local time. Expression: */5 * * * *". In server mode it is the server's local time.
Your own cron expression
A cron expression has five fields: minute, hour, day of month, month, weekday. */10 * * * * means every ten minutes. WebDonkey checks the expression right away:
- For jobs WebDonkey starts, it has to be something WebDonkey can evaluate.
- For jobs in the crontab, the rules of
cronon the server apply. cron does not knowL(last day of the month) or?. A step without a range, like5/10, is read differently by cron or not at all. The dialog then offers the equivalent with the range spelled out: Use … puts it in.
Edit and delete
- The pencil opens Edit remote cron job. If you change How it runs there, a yellow note says what happens to the crontab line when you save.
- The bin asks Delete remote cron job?. For a job in the crontab, WebDonkey removes its line from the crontab on the server and deletes its log there. Other crontab lines stay untouched. For a job WebDonkey starts, WebDonkey no longer starts it, and its log on the server is deleted.
What happens in the background
- Each run appends a header line with the date, the output and the exit code to the log
~/.webdonkey/cron/<id>.logon the server. - For a job in the crontab, WebDonkey writes a line that ends with the marker
# webdonkey:and the name. Before every change WebDonkey keeps a copy of the crontab under~/.webdonkey/cron/backup/(the newest 30 stay). All other lines stay exactly as they were, byte for byte, including lines not written in UTF-8. If the crontab cannot be read, WebDonkey does not change it at all.
Troubleshooting
| What you see | Why | What to do |
|---|---|---|
| New remote cron job is locked | There is no SSH connection. | Add one under Connections. |
| The command must be a single line. | The command contains a line break. | Write it on one line, or create a script. |
| The script file does not exist on the server. | Wrong path. | Pick the file with Browse…. |
| No interpreter for this file found on the server | Neither a #! line nor a matching program. |
Add a #! line to the script or install the program. |
| Run on the server is locked, Not possible here: … | The server has no crontab command. |
Use Triggered by WebDonkey. |
| The crontab on the server could not be read … | Read error on the server. The crontab stayed unchanged. | Save again later and check crontab -l on the server. |
| The crontab on the server is being changed by another operation right now … | A second save is running. | Try again in a moment. |
See also
Who runs the job Premium
Under How it runs you choose who starts a remote cron job when it is due: WebDonkey on your Mac over SSH, or the cron service on the server. Both write the same log on the server; the differences are what the server needs and when the job runs.
Where to find it
In the dialog New remote cron job or Edit remote cron job, the section How it runs. The job's card then says started by WebDonkey or runs on the server.
The two ways
| Triggered by WebDonkey | Run on the server | |
|---|---|---|
| Who starts it | WebDonkey over SSH when it is due | cron on the server from its crontab |
| What the server needs | Nothing but SSH | the crontab command |
| When it runs | While your Mac is on and WebDonkey runs, or with scheduling without the app also while the app is closed | Always, also while your Mac is off |
| Time zone | Your Mac's local time | The server's local time |
| Missed runs | caught up once | by the rules of cron on the server |
| On the card | started by WebDonkey and Next run | runs on the server and in crontab |
Triggered by WebDonkey is the default for new jobs. For such a job to run while the app is closed, set up Run on schedule without the app under Settings › System, see Run without the app open.
If the server has no crontab command, Run on the server is locked and says Not possible here: … below it. While WebDonkey is still checking, it says Checking the server….
How to switch
- Open the job with the pencil.
- Choose the other way under How it runs. A yellow note says what happens when you save.
- Click Save.
- To server mode: saving adds the line to the server's crontab, and WebDonkey no longer starts the job.
- To WebDonkey mode: saving removes the line from the server's crontab; from then on WebDonkey starts the job.
WebDonkey makes sure the job is neither planned twice nor not at all while it switches.
When server and app disagree
Every card compares what WebDonkey expects with the crontab on the server. If they do not match, a yellow box appears on the card:
| What you see | Why | What to do |
|---|---|---|
| The line is missing from the crontab on the server … | The job should run on the server, but its line is gone, removed by hand for example. It does not run. | Apply on the server writes the line again. |
| The job is paused here, but its line is still in the crontab on the server. | The job is paused, but it keeps running on the server. | Apply on the server removes the line. |
| Its line is also in the crontab on the server … | WebDonkey starts the job, and the server runs it as well. It runs twice. | Remove the line takes the line out of the crontab. |
Jobs from another Mac
If WebDonkey finds a WebDonkey line it does not know in a server's crontab, from another Mac for example, it takes it over as a job that runs on the server. For that it looks into the crontab of the server picked and of all servers with jobs when you open the page.
See also
Manage jobs Premium
On a remote cron job's card you start it right away, pause it, read its log and see what else is in the server's crontab. The card also shows how the last run ended.
Where to find it
Sidebar Remote › Cron jobs, the job's card in the section of its server.
How to do it
- Click Run now. The button shows Running… until the job is done.
- Then the Log unfolds and shows the latest output. The mark exit 0 means success. Any other exit code shows in red.
- To pause, click the switch next to Run now. The card then carries paused.
What the card shows
| Part | Meaning |
|---|---|
| Icon | Terminal for a command, file for a script file. |
| Schedule | Such as every minute, every 5 minutes, every hour, daily at 03:00, every Monday at 03:00, or the expression itself. |
| started by WebDonkey / runs on the server | Who starts the job, see Who runs the job. |
| paused | The job is not active. |
| in crontab | The line is in the server's crontab. |
| exit … | The exit code of the last run. |
| Command line | The command, or interpreter and script file. |
| Last run: … | When it last ran. If it never ran, it says Not run yet. While WebDonkey looks, it says Checking the server…. |
| Next run: … | Only for active jobs WebDonkey starts. |
Buttons
| Button | What it does |
|---|---|
| Run now | Runs the job right away, with the same command and into the same log as a scheduled run. WebDonkey waits up to ten minutes for it to end. If the job takes longer, it goes on running on the server. |
| Switch | For a job WebDonkey starts: Pause and Resume. For a job in the crontab: Pause (removes the line) and Resume (adds the line). |
| Pencil | Opens Edit remote cron job, see Create a cron job. |
| Bin | Deletes the job after asking Delete remote cron job?. |
The log
Log unfolds the latest lines of the log, with its path on the server next to it (~/.webdonkey/cron/…log). Each run starts with a header with date and time; a run by hand carries the addition (manual) there. At the end of each run is its exit code. The refresh icon next to Log reads it again. If it is empty, it says No output yet.
Other lines of the crontab
Below a server's jobs, Other lines in this crontab (not from WebDonkey, read-only) unfolds all other lines of the crontab. You see what else runs on the server; you cannot change it here. If there are none, it says No other lines. WebDonkey only touches lines that end with its marker # webdonkey:.
Free and Premium
Without Premium, listing, pausing and deleting stay possible, so you can take jobs off a server where they keep running. Run now, Resume, creating and editing need Premium.
Troubleshooting
| What you see | Why | What to do |
|---|---|---|
| This job is already running … | The job is still running, started from this Mac. | Wait until it is done. |
| Red mark exit 1 or higher | The command ended with an error. | Read the Log. |
| Changing the crontab on the server failed | The server refused the write. | Check permissions and free space on the server. |
| This remote cron job no longer exists. | The job was deleted in the meantime, in another window for example. | Reload the page. |