Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replace crontab file with -e

Tags:

Anyone know a way to give a file into crontab -e ? I cannot use the regular form of crontab giving it a path but still need to replace the whole contents.

Perhaps setting EDITOR to something?

like image 468
cellige Avatar asked Oct 18 '13 15:10

cellige


People also ask

Can you edit crontab file?

When you create a crontab file, it is automatically placed in the /var/spool/cron/crontabs directory and is given your user name. You can create or edit a crontab file for another user, or root, if you have superuser privileges.


1 Answers

You can source cron jobs from a file into your crontab using

crontab /path/to/cron/file/name

To make it more explicit for readability's sake, use the arrow < for sourcing.

crontab < /path/to/cron/file/name

Sourcing the cron jobs this way can throw error errors in crontab file, can't install in case the crontab entry you have are syntactically invalid in terms of scheduling, so make sure the cron entries are correct.

Also note that this will completely discard existing cronjobs and load the ones which are there in the file you pass, so it might help to save existing cron entries in a file using crontab -l > cron.backup

EDIT

In case you are looking for a way to change your default editor (to gedit or vi or something else) and not for a way to source cronjobs from file, you can export the VISUAL and EDITOR Path variables

export VISUAL=vim
export EDITOR=vim
like image 93
Anshul Goyal Avatar answered Sep 27 '22 23:09

Anshul Goyal