<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Colleagues</p>
<p>Thank you to both Rick Brownrigg and Gus Corea for your help with
this problem. Although your specific solutions did not work for
me, they gave me clues about how to solve the problem. Here is a
summary.</p>
<p>Task:</p>
<p>I want to execute a shell script once per day using a cron job.
The shell script downloads the latest GHRSST data from NOAA ERDDAP
using R, and then plots maps from the data using NCL.</p>
<p>Problem:</p>
<p>The shell script failed when NCL was called because the conda
environment ncl_stable was not set up properly.</p>
<p>Solution:</p>
<p>Use conda execute to create a virtual environment for the script
to run in. See
<a class="moz-txt-link-rfc2396E" href="https://pelson.github.io/2015/conda_execute/"><https://pelson.github.io/2015/conda_execute/></a>. As written
on this web page, you need to install conda execute first. Then
you add a few lines of conda execute metadata to the shell script:</p>
<p>#!/bin/bash<br>
# conda execute<br>
# env:<br>
# - ncl_stable</p>
<p>When you call the NCL script be sure to provide the path to NCL
e.g.</p>
<p>/home/smcc/anaconda3/envs/ncl_stable/bin/ncl
/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/ncl/plot_daily_GHRSST-MUR-JPL-L4-GLOB-v4_1_around_New_Zealand.ncl</p>
<p>The shell script can now be called from crontab, e.g.:</p>
<p>58 13 * * *
/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/shell/download_latest_GHRSST_data_from_ERDdap.sh<br>
</p>
<p>-------------------------------</p>
<p>My shell script looks like this:</p>
<p>#!/bin/bash<br>
<br>
# conda execute<br>
# env:<br>
# - ncl_stable<br>
<br>
## download_latest_GHRSST_data_from_ERDdap.sh<br>
<br>
# Use crontab -e to edit the cron file <br>
# (see
<a class="moz-txt-link-freetext" href="https://linux4one.com/how-to-set-cron-jobs-on-ubuntu-18-04/">https://linux4one.com/how-to-set-cron-jobs-on-ubuntu-18-04/</a>)<br>
# use cronitor to troubleshoot cron file <br>
# (see
<a class="moz-txt-link-freetext" href="https://cronitor.io/cron-reference/cron-troubleshooting-guide">https://cronitor.io/cron-reference/cron-troubleshooting-guide</a>). <br>
# Try $ cronitor select to test run<br>
<br>
########################################<br>
# download the latest GHRSST data from erddap<br>
########################################<br>
Rscript
"/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/R/download_GHRSST_MUR-JPL-L4-GLOB-v4.1_daily.R"<br>
<br>
########################################<br>
# plot GHRSST data<br>
########################################<br>
<br>
/home/smcc/anaconda3/envs/ncl_stable/bin/ncl
/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/ncl/plot_daily_GHRSST-MUR-JPL-L4-GLOB-v4_1_around_New_Zealand.ncl<br>
<br>
/home/smcc/anaconda3/envs/ncl_stable/bin/ncl
/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/ncl/plot_daily_GHRSST-MUR-JPL-L4-GLOB-v4_1_around_New_Zealand_bigeye.ncl<br>
<br>
/home/smcc/anaconda3/envs/ncl_stable/bin/ncl
/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/ncl/plot_daily_GHRSST-MUR-JPL-L4-GLOB-v4_1_around_New_Zealand_bluefin.ncl<br>
<br>
/home/smcc/anaconda3/envs/ncl_stable/bin/ncl
/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/ncl/plot_daily_GHRSST-MUR-JPL-L4-GLOB-v4_1_around_New_Zealand_yellowfin.ncl<br>
<br>
-----------------------------------</p>
<p>And here are some of the plots:</p>
<p><a class="moz-txt-link-freetext" href="http://u.pc.cd/K62rtalK">http://u.pc.cd/K62rtalK</a></p>
<p><a class="moz-txt-link-freetext" href="http://u.pc.cd/AbRrtalK">http://u.pc.cd/AbRrtalK</a></p>
<p>--------------------------------</p>
<p>Best fishes for New Year, and thanks!</p>
<p>Sam<br>
</p>
<p><br>
</p>
-- <br>
<div class="moz-signature">
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<title>email signature</title>
Sam McClatchie (fisheries oceanographer)<br>
& Elena Turin (accounting & auditing)<br>
FishOcean Enterprises <span style="text-decoration: underline;"><a
href="http://www.fishocean.info">www.fishocean.info</a></span><br>
38 Upland Rd, Huia, Auckland 0604, New Zealand<br>
cell: 027 752 8495<br>
<!--<span style="text-decoration: underline;"><a href="http://www.fishocean.info">Internet</a></span><br>-->
<img style="width: 150px; height: 149px;" alt=""
src="cid:part2.6E769F6D.91B41CE9@fishocean.info"><br>
<br>
“The three great elemental sounds in nature are the sound of rain,<br>
the sound of wind in a primeval wood, and the sound of outer ocean
on a beach.<br>
I have heard them all, and of the three elemental voices, <br>
that of ocean is the most awesome, beautiful and varied.”<br>
<br>
― Henry Beston, The Outermost House: A Year of Life on the Great
Beach of Cape Cod
</div>
</body>
</html>