Benjamin blog
  • Firebase cloud functions
  • Connect to aws database
  • connect-to-raspberry-pi-np-hdmi
  • Get your logs from your mobile to your desktop
  • Twitter bot
  • Crontab
  • Delete your git history
  • How I hacked my sons Duplo train to go faster using my voice
  • Finetune GTPT-3
  • Create a localhost tunnel
  • Paste clipboard to vim through ssh in Windows
  • Predictions of the future
  • Prisma
  • Connect to Raspberry Pi no HDMI output
Powered by GitBook
On this page
  • Best practice
  • Examples
  • Time examples
  • Write logs to a file

Crontab

To open Crontab write crontab -e

Best practice

So try and cd into the project in crontab and then run your commends. The reason is that running the command directly nearly always gives errors with environment variables, finding files, etc.

Examples

So I have this at the top of my crontab for some reason. I think it was to get all my environment variables working so i fx can reference node without specifying the specific location

PATH=PATH=/usr/local/sbin:/usr/local/bin:/usir/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
# m h  dom mon dow   command
# 00 16 * * * cd /home/YOUR_PROJECT && ./data-deploy.sh >>/home/YOUR_PROJECT/newest-log 2>&1
0 */2 * * * cd /home/YOUR_PROJECT && node ./YOUR_PROJECT.js >>/home/YOUR_PROJECT/newest-log 2>&1

Time examples

16:00 every day

00 16 * * *

Every second hour

0 */2 * * *  /home/username/test.sh

Write logs to a file

You can write the logs of your call like this after your command:

>>/home/YOUR_PROJECT/newest-log 2>&1

So this is piping the logs into the file newest-log

PreviousTwitter botNextDelete your git history

Last updated 3 years ago