LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 06-18-2019, 06:32 AM   #1
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
cannot editor crontab unless I explicitly set the EDITOR


Whenever I try to run crontab -e, I get this random code:
Code:
crontab -e
927

?

?
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.
 
Old 06-18-2019, 07:58 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,258

Rep: Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419
did you check how is it set (by default?)
 
Old 06-18-2019, 08:02 AM   #3
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
You mean the EDITOR variable? It's null.
 
Old 06-18-2019, 08:49 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,258

Rep: Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419
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.
Old 06-18-2019, 08:53 AM   #5
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
Neither EDITOR, nor VISUAL is set. I don't really need a general answer. I'd like a particular answer for my problem
 
Old 06-18-2019, 09:03 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,258

Rep: Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419
And what do you think who knows how that server was installed/configured exactly?
 
Old 06-18-2019, 09:10 AM   #7
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
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.
 
Old 06-18-2019, 11:34 AM   #8
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by vincix View Post
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.
Old 06-18-2019, 01:55 PM   #9
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,775

Rep: Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226
Quote:
Originally Posted by pan64 View Post
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.
 
Old 06-18-2019, 02:22 PM   #10
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,775

Rep: Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226
Quote:
Originally Posted by ehartman View Post
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.
 
Old 06-18-2019, 04:22 PM   #11
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by scasey View Post
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.
Old 06-18-2019, 04:45 PM   #12
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,775

Rep: Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226Reputation: 2226
Re: #11. Outstanding! Thank you for the through and complete explanation!
 
Old 06-19-2019, 01:57 AM   #13
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,258

Rep: Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419Reputation: 7419
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.
 
Old 06-25-2019, 12:04 PM   #14
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,874

Rep: Reputation: 1227Reputation: 1227Reputation: 1227Reputation: 1227Reputation: 1227Reputation: 1227Reputation: 1227Reputation: 1227Reputation: 1227
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.
Old 06-25-2019, 04:53 PM   #15
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by MadeInGermany View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
better to use state firewall or explicitly define what comes back in? dividingbyzero Linux - Security 7 06-04-2008 02:09 PM
is there a way to free the resources of a created frame "explicitly" in java ?? alred Programming 4 06-01-2006 03:11 PM
Users unable to use crontab unless in /etc/shadow atnan Linux - General 2 05-03-2005 11:43 PM
Filecopy Using Sockets Without Explicitly Running Server Side Program. chaits Linux - Networking 3 03-11-2004 02:08 AM
Explicitly setup a PPTP connection for testing within the network csvke Linux - Networking 0 01-25-2004 07:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration