1

I'm using Linux Centos 7, as a non-root user. When I want to add cron job that is not possible, I enter

crontab -e

I don't have option to select editor or to add cron job, just have blue ~ signs??

Also command select-editor does not exist.

Any help? What should I do?

Screenshoot:

http://prntscr.com/qxu06n

  • Can you show us what is the output? – BANJOSA Feb 05 '20 at 10:05
  • What are your VISUAL or EDITOR environment variables (from man crontab)? – RudiC Feb 05 '20 at 10:10
  • 1
    Sounds like you are using vi or vim editor. Are the blue ~ signs in a vertical line on the left? – John Hawthorne Feb 05 '20 at 10:15
  • i uploaded screenshot –  Feb 05 '20 at 10:28
  • 1
    Yes you have. The option as @RudiC mentioned, is setting either VISUAL or EDITOR env. variable prior to run crontab -e. Here's e.g. how: EDITOR=mcedit crontab -e. This will use midnight commander editor. Replace it with the one of your choice. – Tagwint Feb 05 '20 at 10:35
  • First of all, you should press :, q and Enter to get out of the vim editor you're in. Or if you had already pressed the i, a or s keys by mischance, Escape, :, q, ! and Enter. –  Feb 05 '20 at 14:33

2 Answers2

3

That is VIM (or possibly another vi clone). You are in a text editor. To add a cron job, just edit using that editor.

You do not have select-editor because that is part of the "sensible-utils" package on Debian. (Previously it was part of a "debianutils" package which was more obviously Debian-specific.) That package is in the EPEL, not in CentOS proper.

The thing that RedHat has adopted from Debian is the "alternatives" system. That controls what the editor command maps to.

There are several possibilities:

  • Your VISUAL environment variable points to vim (or vi).
  • Your VISUAL environment variable points to editor, and the currently selected alternative for editor is VIM.
  • Your VISUAL environment variable is unset, the fallback is editor, and the currently selected alternative for editor is VIM.
  • Your VISUAL environment variable is unset, the fallback is vim (or perhaps vi).

There are two approaches to changing the editor, if you want to use another one:

  • Change what your VISUAL environment variable points to. Depending from how you set it in the shell, this changes full-screen editor for just the current interactive shell session, or even just the current command (if you assign the variable as a prefix to a simple command). You can of course set it in a login script.
  • Unset your VISUAL environment variable and change the alternative for editor. This changes the meaning of editor for everyone on the system, note. It also depends from the assumption that editor is the fallback when the environment variable is unset. That's a reasonable fallback to use on "alternatives" operating systems like Debian, OpenSUSE, and Fedora/CentOS/RHEL. But the fallback logic is of course encoded in many individual commands and scripts and not every software author chooses editor as the fallback.

Further reading

JdeBP
  • 68,745
1

To use a different editor, for example nano, for a one-time edit, run:

EDITOR=nano crontab -e

To make nano your default editor, add this to your profile which may be .bashrc or some other file:

export VISUAL="nano"
export EDITOR="nano"

Then reload your profile with :

source ~/.bashrc

https://www.redhat.com/sysadmin/getting-started-nano