[ncl-talk] running NCL on a cron invokes wrong NCL version

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Fri Jul 24 14:47:08 MDT 2020


I am glad you got it working.  For the record, I may have been mistaken in
suggesting "setenv PATH".  This would work only if your cron invokes C
shell.  If it is bash, then you would use "PATH=" etc.  Alternatively, I
think there is a way to dynamically switch to a different shell in the cron
job.

Use commands "env" and "set" to capture information about your current
shell and its environment.


On Fri, Jul 24, 2020 at 2:26 PM Diana Stovern - NOAA Affiliate <
diana.stovern at noaa.gov> wrote:

> Thanks for the help, Dave!  Adding the path to the cron didn't work, but
> adding it to the python script that calls ncl did work.  These were the key
> pieces I added to my python script so that the cron didn't fail:
>
> os.environ["NCARG_ROOT"]='/usr/local/ncl-6.6.2'
> os.system('/usr/local/ncl-6.6.2/bin/ncl ' + regrid_script)
>
> Cheers!
> Diana
>
> On Wed, Jul 22, 2020 at 5:51 PM Dave Allured - NOAA Affiliate <
> dave.allured at noaa.gov> wrote:
>
>> What is probably happening is that cron is skipping your normal shell
>> startup script such as .cshrc or .bashrc.  This is normal cron behavior.
>> If your normal startup script sets $PATH or an alias affecting NCL, and is
>> skipped, then your cron job may find an older version in a system default
>> path such as /usr/bin.
>>
>> At the start of your cron job, add an environment command like "setenv
>> PATH", or possibly invoke your normal startup script, to get your expected
>> NCL environment.  This is also probably the right place to set NCARG_ROOT,
>> to reduce hard coded dependencies in your application code.
>>
>> Here is an article with more details.  See the first paragraph under
>> "Notes and warnings" near the bottom.
>>
>>
>> https://drupal.star.bnl.gov/STAR/blog/jeromel/2013/apr/05/how-setup-crontabs
>>
>>
>> On Wed, Jul 22, 2020 at 4:21 PM Diana Stovern - NOAA Affiliate via
>> ncl-talk <ncl-talk at mailman.ucar.edu> wrote:
>>
>>> Hello all,
>>>
>>> Has anyone ever had issues running NCL on a cron via a python script?
>>> For example, I wrote a python script that calls a bunch of NCL scripts
>>> using the os.system command (i.e., os.system('ncl ' + regrid_script.ncl).
>>> I define the NCARG_ROOT environment in the python script like the help
>>> forums on this topic suggest with the following code:
>>>
>>> os.environ["NCARG_ROOT"]='/usr/local/ncl-6.6.2'
>>>
>>> Running the python script from the terminal always invokes NCL 6.6.2.
>>> However, the NCL version that is invoked from the cron is a really old
>>> version (6.3.0).  I recently had 6.6.2 installed so I could take advantage
>>> of the ESMF regridding routines.
>>>
>>> My question is, does anyone know why the cron invokes the old version of
>>> NCL and not the new version specified in the python script?  This is really
>>> causing problems because the python script tries to run the NCL scripts
>>> with version 6.3.0, but looking in directories associated with 6.6.2, thus
>>> errors arise and the script crashes.
>>>
>>> Has anyone experienced this issue before and have a quick fix?  How do I
>>> get the cron to invoke 6.6.2 instead of 6.3.0?
>>>
>>> Any advice is greatly appreciated!
>>>
>>> - Diana Stovern
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200724/3077894c/attachment.html>


More information about the ncl-talk mailing list