Monday, May 18, 2009

Solaris Crontab exporting an environment variable

Ran into a problem when exporting an environment variable in solaris.

If your bash script has the following code:
export JETTY_HOME=/opt/os/home/efaitan/Desktop/hightide

You would get the following error:
JETTY_HOME=/opt/os/home/efaitan/Desktop/hightide: is not an identifier


This is because cron is run by bourne shell and for that this is not a valid syntax. Bascially you are telling it to export a variable identified as "JETTY_HOME=/opt/os/home/efaitan/Desktop/hightide:" where all you wanted was to export the variable JETTY_HOME.

Resolution: Use two lines instead of one. Modify your script to :
JETTY_HOME=/opt/os/home/efaitan/Desktop/hightide
export JETTY_HOME

Further detail:
The default shell opened for my solaris system was KSH. You can determine the default shell using the $SHELL environment variable. The above export and set in one line in valid for ksh but not valid for bourne shell (normal sh).

It is suggested that you test your scripts in sh before adding them in crontab entries.
Here is a screen shot explaining the root cause of the error:


Enjoy!

No comments:

Post a Comment