Details
OS: Solaris 10 , update 11
HW: M5-32 LDOM, V490, IBM x3650, T5240, VMware virtual machine, etc...
EDITOR=vi
term=vt100
tmp directory=/var/tmp
cron shell=/sbin/sh
My shell=/bin/bash
Issue
A very interesting error occurs when attempting to modify the crontab via crontab -e
.
If I attempt to search for a non-existent string utilizing crontab -e
to verify and check syntax with vi as my editor, and then try and save, it will puke back and tell me an error has occurred even if no changes were made.
Example
admin@server# export EDITOR=vi
admin@server# crontab -e
In command mode, search for a non-existent string like "foobar123". After receiving the "Pattern not found" then attempt to :wq
and you'll receive...
The editor indicates that an error occurred while you were
editing the crontab data - usually a minor typing error.
Edit again, to ensure crontab information is intact (y/n)?
('n' will discard edits.)
If you are cheeky and choose to go right back in and attempt to save it will now save sans error. This is repeatable from on all types of Solaris from VMware to M5-32 LDOM, to a V490 physical. Curious as to why cron would interpret a search for a non-existent string as an error, but not say visudo
.
A related note is Solaris 11 will not produce this error, which then begs the question if this is some sort of POSIX specification why it would apply to Solaris 10 and not 11?
:wq
? What happens if you use a differentEDITOR
besides vi? I'm thinking that vi has a tendency to add a newline to the end of the file if there isn't one already, and this might somehow be the source of your issue. – jayhendren Nov 28 '16 at 18:43If I search for nothing and save, it will save without producing any error. Whether you make edits or don't doesn't affect it saving correctly until you attempt that non-existent search. A search for an existing string and then
:wq
will also save correctly.EDIT: Just saw that vi is a link to vim on Solaris 11 which would tend to support a
– Sending_Grounds Nov 28 '16 at 18:49vi
specific issue. Tried on about 20 systems so far all with the same result.:Wq
and some other variations in vi to the same effect;vi
returns a non-zero for almost any bad command in command mode.Which explains why when you say 'y' and reopen the crontab and immediately save, it's a new session with a different exit code of '0' and therefore cron allows you to continue.
Strange that
– Sending_Grounds Nov 28 '16 at 21:16visudo
doesn't have similar behavior, or maybe sudo doesn't care about the return value ofvi
the same way cron does.