Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
06-18-2019, 06:32 AM
|
#1
|
Senior Member
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,247
Rep: 
|
cannot editor crontab unless I explicitly set the EDITOR
Whenever I try to run crontab -e, I get this random code:
When I press enter, the ? shows up.
It works if I run the command with EDITOR=vim before it, but I'd like to understand what is happening. I know that the EDITOR variable doesn't necessarily need to be set, in order to get a default editor.
update-alternative --config editor doesn't work either. I get these choices:
Code:
Selection Path Priority Status
------------------------------------------------------------
* 0 /bin/nano 40 auto mode
1 /bin/ed -100 manual mode
2 /bin/nano 40 manual mode
3 /usr/bin/vim.basic 30 manual mode
4 /usr/bin/vim.tiny 10 manual mode
I know I could also simply add the EDITOR variable into my .bashrc or whatever, but I'd like to understand the behaviour. Thanks.
I'm running Ubuntu 16.04.4
Last edited by vincix; 06-18-2019 at 06:45 AM.
|
|
|
06-18-2019, 07:58 AM
|
#2
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,656
|
did you check how is it set (by default?)
|
|
|
06-18-2019, 08:02 AM
|
#3
|
Senior Member
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,247
Original Poster
Rep: 
|
You mean the EDITOR variable? It's null.
|
|
|
06-18-2019, 08:49 AM
|
#4
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,656
|
you need to read the man page, you will see either EDITOR or VISUAL is used. And there is also a default (if both of them are unset). But it looks like it depends on the distro, so there is no general answer.
|
|
1 members found this post helpful.
|
06-18-2019, 08:53 AM
|
#5
|
Senior Member
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,247
Original Poster
Rep: 
|
Neither EDITOR, nor VISUAL is set. I don't really need a general answer. I'd like a particular answer for my problem 
|
|
|
06-18-2019, 09:03 AM
|
#6
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,656
|
And what do you think who knows how that server was installed/configured exactly?
|
|
|
06-18-2019, 09:10 AM
|
#7
|
Senior Member
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,247
Original Poster
Rep: 
|
Well, that's why I'm writing on this forum, maybe someone has an idea about what might have led to this. This isn't the first time I've seen this - and it was on a completely different server.
Last edited by vincix; 06-18-2019 at 09:13 AM.
|
|
|
06-18-2019, 11:34 AM
|
#8
|
Senior Member
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674
|
Quote:
Originally Posted by vincix
When I press enter, the ? shows up.
|
Looks like your version of crontab is using "ed" by default, and as you saw ed is VERY minimal, no prompts, no visual mode, it essentially only supports the commands "sed" does too (in fact sed - the Stream EDitor - is derived FROM ed).
ex, the "command mode" of vim, features an extended set of commands compared to ed (ex stands for EXtended editor, vi then was a later VIsual mode on top of ex and still later there came vim, vi iMproved).
THE thing with ed is, every Unix (and Unix-like O/S like Linux or *BSD) is guaranteed to have a copy around, so it is a reasonable default to compile in when no alternative editor has been set.
Last edited by ehartman; 06-18-2019 at 11:37 AM.
Reason: typing errors
|
|
2 members found this post helpful.
|
06-18-2019, 01:55 PM
|
#9
|
LQ Veteran
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: Rocky 9.6
Posts: 5,906
|
Quote:
Originally Posted by pan64
you need to read the man page, you will see either EDITOR or VISUAL is used. And there is also a default (if both of them are unset). But it looks like it depends on the distro, so there is no general answer.
|
Now I'm curious, too.
I'm on CentOS 7. Both EDITOR and VISUAL are unset, but crontab -e works just fine and uses vi, so that's apparently the default, but I'm not finding what manages that default in CentOS. Searches lead to "if you want to change the default, then set EDITOR and VISUAL" without (so far) leading me to where that default happens. I'd appreciate a hint
I see the OP is using Ubuntu, so even if I figure it out, it may not help them.
|
|
|
06-18-2019, 02:22 PM
|
#10
|
LQ Veteran
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: Rocky 9.6
Posts: 5,906
|
Quote:
Originally Posted by ehartman
Looks like your version of crontab is using "ed" by default, and as you saw ed is VERY minimal, no prompts, no visual mode, it essentially only supports the commands "sed" does too (in fact sed - the Stream EDitor - is derived FROM ed).
ex, the "command mode" of vim, features an extended set of commands compared to ed (ex stands for EXtended editor, vi then was a later VIsual mode on top of ex and still later there came vim, vi iMproved).
THE thing with ed is, every Unix (and Unix-like O/S like Linux or *BSD) is guaranteed to have a copy around, so it is a reasonable default to compile in when no alternative editor has been set.
|
Aha. You're implying then (if I'm reading you correctly), that the "default" is compiled into something (the kernel?) and it's not, therefore changeable except by setting VISUAL and/or EDITOR (I'm seeing that VISUAL is what crontab looks at first, but I'm also finding lots of places that say set them both the same). That's probably why I can't find where the default is set.
If I've go that right, then the OPs answer (and mine), is to set those environment variables to the desired editor. Yes?
Last edited by scasey; 06-18-2019 at 02:23 PM.
|
|
|
06-18-2019, 04:22 PM
|
#11
|
Senior Member
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674
|
Quote:
Originally Posted by scasey
Aha. You're implying then (if I'm reading you correctly), that the "default" is compiled into something
|
It is compiled into the "crontab" executable, to have a "sensible default" for the crontab -e command and as there are almost as many different implementations of cron (and thus crontab) as there are (major) distributions (vixieCron, anacron, Dillon cron, etc) and every package builder can specify his own preferred default into the compilation, there is not a single answer for all possible crontab program's.
I.e. in "my" version of crontab there is this string "/usr/bin/vi", so the compiled-in default is "standard vi", not vim.
PS: found with "strings `which crontab`|grep /bin/" (which in MY case had to be as root as the crontab executable is not readable (although executable) by normal users):
Code:
-rws--x--x 1 root root 10096 2012-09-07 22:24 /usr/bin/crontab
BTW: Slackware is using dillon's lightweight cron daemon.
The man page for "crontab" for that package gives:
Quote:
Generally the -e option is used to edit your crontab. crontab will use the editor specified by your EDITOR or VISUAL environment variable (or /usr/bin/vi) to edit the crontab.
|
so that man page is adjusted to the compiled-in default.
Last edited by ehartman; 06-18-2019 at 04:26 PM.
Reason: Addition from the man page
|
|
2 members found this post helpful.
|
06-18-2019, 04:45 PM
|
#12
|
LQ Veteran
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: Rocky 9.6
Posts: 5,906
|
Re: #11. Outstanding! Thank you for the through and complete explanation!
|
|
|
06-19-2019, 01:57 AM
|
#13
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,656
|
based on the man page you find (depends on the version of crontab) it is:
1. compiled into the executable as explained in post #1., but unfortunately it is not all, because
2. sometimes /etc/alternatives/editor is used
3. /usr/bin/editor (or /usr/bin/sensible-editor) is used
4. you can use some tools like update-alternatives or select-editor to configure it
5. whatever else ....
6. if EDITOR and VISUAL are not set.
And finally the garbage was produced because the editor used has no idea about the [type of the] terminal itself and the default term selected by that editor is not compatible with the actual one.
|
|
|
06-25-2019, 12:04 PM
|
#14
|
Senior Member
Registered: Dec 2011
Location: Simplicity
Distribution: Mint/MATE
Posts: 3,052
|
Unfortunately the man page is poor, does not tell what the compiled-in default editor is.
You can try the following hack:
Code:
strings /usr/bin/crontab | grep /bin/
|
|
1 members found this post helpful.
|
06-25-2019, 04:53 PM
|
#15
|
Senior Member
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674
|
Quote:
Originally Posted by MadeInGermany
Unfortunately the man page is poor, does not tell what the compiled-in default editor is.
|
That is one of the differences between all of the varying implementations of cron (and crontab) too. Sometimes the "editor" specified in the "configure" part of building the package it is put into the generated man page too, sometimes it isn't.
Code:
strings /usr/bin/crontab | grep /bin/
That's what I used too, although I didn't use the absolute path, but `which crontab`, for distro's that put it somewhere else.
|
|
|
All times are GMT -5. The time now is 04:31 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|