1848232 Members
6705 Online
104022 Solutions
New Discussion

Editor for cronjob!

 
SOLVED
Go to solution
leereg_6
Advisor

Editor for cronjob!

Hi, Gurus,

When I try to add an entry to the crontab, the default editor is ed. But when I first login with normal user, the default editor is vi, after I su to root, the default editor for crontab changed to ed. But for other SA, the did not happen to this. How can I change the default editor to vi?
# crontab -e
1959
^C
?
# ps -ef|grep crontab
root 5574 5146 0 09:51:06 pts/5 0:00 crontab -e
root 5576 5575 0 09:51:07 pts/5 0:00 sh -c ed /tmp/crontab0JMYv0
root 5575 5574 0 09:51:06 pts/5 0:00 crontab -e
root 5577 5576 0 09:51:07 pts/5 0:00 ed /tmp/crontab0JMYv0
root 5621 5615 0 09:51:44 pts/6 0:00 grep crontab


Thanks in advance!
7 REPLIES 7
George Morrison
Frequent Advisor

Re: Editor for cronjob!

per the man page on crontab, the editor used when running crontab -e is determined by the EDITOR environment variable. If you use POSIX/Korn shell, you can type

export EDITOR=vi
crontab -e

To fix the problem permanently, set the EDITOR variable in your shell's startup script (.profile for Bourne/Kron/POSIX, .login for csh;note the syntax for setting EDITOR is different for csh).
Michael Tully
Honored Contributor
Solution

Re: Editor for cronjob!

Another way is to use 'set' which is part of the shell.

To inquire:
# set -o
Current option settings
allexport off
bgnice on
emacs off
errexit off
gmacs off
ignoreeof off
interactive on
keyword off
markdirs off
monitor on
noexec off
noclobber off
noglob off
nolog off
nounset off
privileged off
restricted off
trackall off
verbose off
vi on
viraw off
xtrace off

# set -o vi (to turn it on)

One other thing. New ver us 'crontab -e' to make changes to 'crontabs'.
Always use:
# crontab -l >/tmp/wrk (work file)
make your changes, save the file.
# crontab /tmp/wrk

If something goes wrong with your session, you have a better chance of saving your crontab file from becoming corrupted.
Anyone for a Mutiny ?
leereg_6
Advisor

Re: Editor for cronjob!

Thanks a lot, George!
When I su to root from normal user usr001 with the following command:
$su
passwd:xxxxxxx
and the default editor is vi. This is correctly what I want.
but when I su to root with the command:
$su -
passwd:xxxxxxx
and the prompt for #echo $EDITOR
is blank. And the default editor for crontab is ed.
So the question can be swithed to:
What's the difference between
su and su -?
Michael Tully
Honored Contributor

Re: Editor for cronjob!

The difference is:

su - (picks up the environment set for root, basically uses root's .profile.)

su (just makes you root, but does not include root's environment.)
Anyone for a Mutiny ?
Patrick Wallek
Honored Contributor

Re: Editor for cronjob!

Somewhere along the line when you do the 'su -' when it is sourcing roots .profile or /etc/profile, the EDITOR environment variable is getting unset. You just need to modify the .profile or make your own environment file with your personal setting that you can source so your environment is setup like you want it to be.
leereg_6
Advisor

Re: Editor for cronjob!

Thanks a lot for all your input!
I still can not change that.

After I add the line
export $EDITOR=vi
input root .profile and I su to root.It prompt:
hosta:/home/usr001 >> su -
Password:


##########################################################################

You have new mail.
-sh: syntax error: `PLATFORM=$' unexpected
-sh: =vi: is not an identifier



How to get it on the right way!

Thanks a lot!
Michael Tully
Honored Contributor

Re: Editor for cronjob!

Set it up like this, not $EDITOR

# Set up the shell variables:
PATH=$PATH:/usr/bin:/sbin
EDITOR=vi
export PATH EDITOR
Anyone for a Mutiny ?