DEV Community

Ángel Blanco
Ángel Blanco

Posted on

TISO #01 🤯 crontab -e != sudo crontab -e

Welcome to TISO (Today I Stack-Overflow-ed)! This a post series where I share what I learnt after facing a weird bug on my code or an unexpected behavior on my machine, in hopes that you also learn from it. Feedback and comments are welcome!

Today I was trying to configure a Linux server to run a NodeJS service on every boot using Cron and Crontab. The shell command to edit the Crontab file where you schedule the tasks is crontab -e. But then, while playing around with Crontab, I stumbled upon something unexpected:

Running crontab -e opens a different Crontab file than sudo crontab -e! If you add some cron tasks on the first one, they won't appear in the latter, and vice versa.

This is because when you run the command without sudo, you will add tasks as the current logged in user. But if you add sudo then you will add tasks to another Crontab that executes with root user's permissions. Quite dangerous!

Did you know this already? Is there something else you want to add? Feel free to say it in the comments! ⬇

Original source: https://stackoverflow.com/questions/43237488/linux-difference-between-sudo-crontab-e-and-just-crontab-e

Top comments (0)