Wednesday, July 22, 2009

How to edit CRONTAB file on Solaris

I rarely edit crontab files on our Solaris machines but then when I need to add or edit something I always experience the same problem and always searching for an answer 5-10 minutes. This time I will write solution in blog post for quick reminder.

Problem is, when I execute "crontab -e" to edit current crontab file I don't get editor window.
I get something like this:

bash-2.05$ crontab -e
135




My problem is that I don't have EDITOR environment variable set.

I have to do something like this:

bash-2.05$ export EDITOR=vi
bash-2.05$ crontab -e

#Then I will receive proper output to edit crontab file
30 21 * * * /opt/oracle/product/9.2.0/local/script1
30 22 * * * /opt/oracle/product/9.2.0/local/script2



To avoid this problem happening any more I will add EDITOR environment variable in my ".profile" file:

bash-2.05$ cd ~
bash-2.05$ vi .profile


#!/bin/ksh
set -am -o vi
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/9.2.0
export PATH=$PATH:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export EDITOR=vi
export ORACLE_SID=db
exec bash


Now, every time I login on this machine environment variable for EDITOR will be automatically set and I won't have problems with "crontab -e" any more.

5 comments:

  1. Cron is a unix, solaris utility that allows tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs in unix , solaris. Crontab (CRON TABle) is a file which contains the schedule of cron entries to be run and at specified times.

    ReplyDelete
  2. Good post, thanks for the tip.

    ReplyDelete
  3. Thanks for the post - noticed that:

    export EDITOR=vi

    gave an error

    EDITOR=vi: is not an identifier

    so:

    EDITOR=vi
    export EDITOR

    albeit didn't get as far as adding it to .profile

    ReplyDelete
  4. Yes, if you're using Solaris sh then this two steps are needed.

    You can also add this two steps in .profile.

    Thanks for comment!

    Regards,
    Marko

    ReplyDelete
  5. Thank you! Very helpful.

    ReplyDelete