Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/recipes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
* [Run Grunt Tasks from Gulp](run-grunt-tasks-from-gulp.md)
* [Exports as tasks](exports-as-tasks.md)
* [Rollup with rollup-stream](rollup-with-rollup-stream.md)
* [Run gulp task via cron job](cron-task.md)
25 changes: 25 additions & 0 deletions docs/recipes/cron-task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Run gulp task via cron job

While logged in via a user that has privileges to run `gulp`, run the following:

crontab -e

to edit your current "[crontab](https://en.wikipedia.org/wiki/Cron)" file.

Typically, within a cron job, you want to run any binary using absolute paths,
so an initial approach to running `gulp build` every minute might look like:

* * * * * cd /your/dir/to/run/in && /usr/local/bin/gulp build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the * * * * *?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that is a cron thing. Before the actual command you want to run, you have to specify the schedule for the command. That is, how often a command should run:

# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │                                       7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * *  command to execute

Per What does * * * * * (five asterisks) in a cron file mean?,

Every minute of every day of every week of every month, that command runs.

I figured I would use that rather some some arbitrary "run once a day at midnight" or something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Thanks


However, you might see in the cron logs that you get this error:

> `/usr/bin/env: node: No such file or directory`

To fix this, we need to add a [symbolic link](https://en.wikipedia.org/wiki/Ln_\(Unix\))
within `/usr/bin` to point to the actual path of our node binary.

Be sure you are logged in as a **sudo** user, and paste in the following command to your terminal:

sudo ln -s $(which node) /usr/bin/node

Once this link is established, your cron task should run successfully.