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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With