0

I am using a fresh installation of Ubuntu 16.04 LTS.
Whenever I type:

sudo crontab -e

OR

sudo -u www-data crontab -e

The command prints some number and nothing else. And whatever you do to try to exit from it, by any means, you are not able to do.

Questions

  • First of all, How to exit from above command? I am just stuck.
  • Why the command is not showing the crontab entries?
  • How to make the above command to show crontab entries?

EDITED
I have chosen the editor as vim.basic with:

sudo update-alternatives --config editor

But when I do echo $EDITOR prints empty.

Also,
crontab -e -> works fine
sudo -u www-data crontab -e -> stuck as mentioned above

  • CROSS POST? This is the only place I have posted. – MagePsycho Feb 24 at 7:46
  • IRC n Forums are two different entities. – MagePsycho Feb 24 at 8:03
  • @MagePsycho If it responds to ESC and then : type of key sequence, then it's vim, so use ESC then : then q to exit. – Sergiy Kolodyazhnyy Feb 24 at 8:19
  • Stupid question: Why didn't you install Ubuntu 18.04 LTS? – Freddy Feb 24 at 8:43
  • This is in the production server. And I have running my sites on 16.04 LTS. Will try 18.04 though in future. – MagePsycho Feb 24 at 8:57
3

I would guess that your default editor is not set and is defaulting to ed.

What do you get if you run:

env | egrep 'EDITOR|VISUAL'

sudo env | egrep 'EDITOR|VISUAL'

sudo -u www-data env | egrep 'EDITOR|VISUAL'

The way to quit from ed is to type: qCR

To set a different editor, you could do:

sudo -u www-data EDITOR=$EDITOR crontab -e
  • It shows blank in both the cases. – MagePsycho Feb 24 at 8:12
  • CR? You don't mean carriage return (\r), right? Shouldn't that be "enter"? – terdon Feb 24 at 14:18
  • I mean the key with the down-left arrow but I don't know how the html for that arrow. Also known as the return key. en.wikipedia.org/wiki/Enter_key – jhnc Feb 25 at 3:27
3

First of all, How to exit from above command? I am just stuck.

We don't know what editor you are using. Try Esc :q (vim) or Ctrl-x (nano) or Ctrl-x Ctrl-c (emacs) or q (ed).

  • Run command select-editor and choose an editor you want to use
  • Alternative: set environment variable EDITOR or VISUAL to an editor of your liking.
    Example: export EDITOR=emacs to use emacs or export EDITOR=nano for nano.
  • Then, run crontab -e to edit your crontab
  • Use crontab -l to show the content of your crontab
  • I am logged in as sudo user. echo $EDITOR -> gives blank. – MagePsycho Feb 24 at 8:04
  • Yes, that's the default. What does select-editor tell you? – Freddy Feb 24 at 8:05
  • I have added more details. Please check. – MagePsycho Feb 24 at 8:08
  • 1
    Login as www-data and add the environment variable to ~/.profile using echo -e "\nexport EDITOR=vim" >> ~/.profile. Then logout. Then try sudo -u www-data crontab -e again. – Freddy Feb 24 at 8:21
  • I have many users for crontab entries. Is there a way to set the default for all (system wide)? – MagePsycho Feb 24 at 8:23
1

I have applied the following commands

# Interactive way
update-alternatives --config editor
# And choose 3 (vim.basic)

# Non Interactive way
sudo update-alternatives --set editor /usr/bin/vim.basic

# Verify as
sudo update-alternatives --query editor

Alternatively, you can add it in ~/.bashrc or ~/.bash_profile file and reload to reflect the changes.

export VISUAL=vim
export EDITOR="$VISUAL"

For crontab for www-data user, I am using as:

sudo crontab -u www-data -e

And this fixed the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.