Posts Tagged ‘crontab’

Linux Crontab: 15 Awesome Cron Job Examples

September 3, 2011 Leave a comment
Categories: bash Tags: , ,

Crontab and vim – No syntax highlighting

June 30, 2011 2 comments

crontab -e displays the cron jobs but there is no syntax highlighting. But .vimrc has syntax on. When I run vim the syntax highlighting kicks in. So the issue was with the editor that crontab uses.

shell> man crontab

-e This option is used to edit the current crontab using the editor
specified by the VISUAL or EDITOR environment variables. After
you exit from the editor, the modified crontab will be installed

Check if the EDITOR variable is set to vim. If not, then that is where the problem is.

1. How to check?

shell> set | grep EDITOR

If it returns blank or points to a different editor apart from vim then change it. Note that by default if the variable is not set, it will use vi. And that might be why the syntax does not show. There are also stripped down versions of vim eg vim-tiny that does not have syntax highlighting. (Unfortunately, I was not able to discover what editor crontab used.)

shell> which vim
shell>export EDITOR
shell> set | grep EDITOR

That should set your Editor to be vi for that session only. If you log out and log in your changes will be lost.

Making your change permanent.
1. Add the following to ~/.bash_profile (For that particular user) or to /etc/profile (For all users).

export EDITOR


NB. I had this problem on a Red Hat server.

Categories: bash Tags: ,