Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not edit cronjobs file in Debian with crontab -e

Tags:

crontab

I have had several Debian servers and always edited cronjobs in this way:

crontab -e and Ctrl+x

Just got a new server and can not do it in this way anymore.

When I enter crontab -e, the file opens but I can't write anything. I can move cursor up and down but can't write. I even can not exit from this file because Ctr+x doesn't work.

When I open a file there is some information and the rest empty lines contain tildes ~ in the beginning of each line.

Any ideas how can I edit this file?

Thanks.

like image 411
user1821484 Avatar asked Nov 16 '12 13:11

user1821484


People also ask

How do I allow user to edit crontab?

To verify if a specific user can access the crontab command, use the crontab -l command while you are logged into the user account. Either this user either is listed in the cron. allow file (if the file exists), or the user is not listed in the cron. deny file.

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.


2 Answers

As one other person has suggested, vim is obviously the default editor on your new server. You can test this by running

EDITOR=pico crontab -e

Substituting whatever is your actual preferred editor (sounds like it may be nano or pico). If that works, you should try one of the following:

  1. edit your login script to set that environment variable on login (sets the editor just for that user)
  2. Make sure your favourite editor is is installed and run the following (as root): update-alternatives --config sensible-editor

You can then choose the default editor for all users (they can override it individually by doing option 1).

like image 74
itsbruce Avatar answered Oct 09 '22 07:10

itsbruce


You need to turn on insert mode. After entering crontab -e, press i to turn on insert, enter your full line, press esc to finish entering, and then hold down shift and press z twice to save the file. This is how I managed to do it in vi/vim

like image 24
shea Avatar answered Oct 09 '22 07:10

shea