<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p><font face="TeX Gyre Adventor">Colleagues</font></p>
<p><font face="TeX Gyre Adventor">[I am using Ubuntu 18.04]<br>
</font></p>
<p><font face="TeX Gyre Adventor">I want to call an NCL script from
a bash shell script. Normally I would just activate the
environment from the command line:</font></p>
<p><font face="TeX Gyre Adventor">(base) smcc@Jaguar:~$ conda
activate ncl_stable<br>
(ncl_stable) smcc@Jaguar:~$ <br>
</font></p>
<p><font face="TeX Gyre Adventor">and then run the shell script in
the terminal:</font></p>
<p><font face="TeX Gyre Adventor">./download_latest_GHRSST_data_from_ERDdap.sh</font></p>
<p><font face="TeX Gyre Adventor">This works fine.<br>
</font></p>
<p><font face="TeX Gyre Adventor">The problem is that I want to
automate by using a shell script called in a cron job. </font><font
face="TeX Gyre Adventor"><font face="TeX Gyre Adventor">I want
to incorporate this NCL script in a cron job containing other
calls to R, so being able to activate the NCL environment from
within a shell script would be helpful. I suspect others have
done something similar, so I'd appreciate your guidance.</font></font></p>
<p><font face="TeX Gyre Adventor">### details follow
#########################<br>
</font></p>
<p><font face="TeX Gyre Adventor">When I try to activate the NCL
environment from a bash shell script using:</font></p>
<p><font face="TeX Gyre Adventor">/home/smcc/anaconda3/bin/conda
activate ncl_stable</font></p>
<p><font face="TeX Gyre Adventor">in the shell script, the following
error is returned: <br>
</font></p>
<p><font face="TeX Gyre Adventor">(base)
smcc@Jaguar:/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/shell$
./download_latest_GHRSST_data_from_ERDdap.sh <br>
<br>
Error message start ---------------------------</font></p>
<p><font face="TeX Gyre Adventor">CommandNotFoundError: Your shell
has not been properly configured to use 'conda activate'.<br>
To initialize your shell, run<br>
<br>
$ conda init <SHELL_NAME><br>
<br>
Currently supported shells are:<br>
- bash<br>
- fish<br>
- tcsh<br>
- xonsh<br>
- zsh<br>
- powershell<br>
<br>
See 'conda init --help' for more information and options.<br>
<br>
IMPORTANT: You may need to close and restart your shell after
running 'conda init'.<br>
<br>
./download_latest_GHRSST_data_from_ERDdap.sh: line 19: ncl:
command not found<br>
(base)
smcc@Jaguar:/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/shell$
<br>
</font><font face="TeX Gyre Adventor"><font face="TeX Gyre
Adventor">Error message end </font>--------------------------------------------<br>
</font></p>
<p><font face="TeX Gyre Adventor">Running conda init bash before
calling the shell script does not fix the problem. <br>
</font></p>
<p><font face="TeX Gyre Adventor"><font face="TeX Gyre Adventor">(ncl_stable)
smcc@Jaguar:/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/shell$
conda init bash<br>
no change /home/smcc/anaconda3/condabin/conda<br>
no change /home/smcc/anaconda3/bin/conda<br>
no change /home/smcc/anaconda3/bin/conda-env<br>
no change /home/smcc/anaconda3/bin/activate<br>
no change /home/smcc/anaconda3/bin/deactivate<br>
no change /home/smcc/anaconda3/etc/profile.d/conda.sh<br>
no change /home/smcc/anaconda3/etc/fish/conf.d/conda.fish<br>
no change /home/smcc/anaconda3/shell/condabin/Conda.psm1<br>
no change
/home/smcc/anaconda3/shell/condabin/conda-hook.ps1<br>
no change
/home/smcc/anaconda3/lib/python3.7/site-packages/xontrib/conda.xsh<br>
no change /home/smcc/anaconda3/etc/profile.d/conda.csh<br>
no change /home/smcc/.bashrc<br>
No action taken.</font></font></p>
<p><font face="TeX Gyre Adventor"><font face="TeX Gyre Adventor">Another
recommendation was to prepend a line to the bash script:</font></font></p>
<p><font face="TeX Gyre Adventor"><font face="TeX Gyre Adventor">eval
"$(command conda 'shell.bash' 'hook' 2> /dev/null)"</font></font></p>
<p><font face="TeX Gyre Adventor"><font face="TeX Gyre Adventor">but
this doesn't seem to work when I call the shell script from
cron. <br>
</font></font></p>
<p><font face="TeX Gyre Adventor"><font face="TeX Gyre Adventor">My
cron file is just one line calling the shell script to run
interactively:</font></font></p>
<p><font face="TeX Gyre Adventor"><font face="TeX Gyre Adventor">0
12 * * * bash -i
/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/shell/download_latest_GHRSST_data_from_ERDdap.sh</font></font></p>
<p><font face="TeX Gyre Adventor"><font face="TeX Gyre Adventor">and
here is my shell script:</font></font></p>
<p><font face="TeX Gyre Adventor"><font face="TeX Gyre Adventor">start
shell script ------------------------------</font></font></p>
<p><font face="TeX Gyre Adventor"><font face="TeX Gyre Adventor">eval
"$(command conda 'shell.bash' 'hook' 2> /dev/null)"<br>
#!/bin/bash<br>
## download_latest_GHRSST_data_from_ERDdap.sh<br>
# NOTE: for this script to work, call the script in cron
using: <br>
# "bash -i ./download_latest_GHRSST_data_from_ERDdap.sh"<br>
# to run the script in interactive mode so the .bashrc file is
sourced<br>
# Otherwise conda activate will not work<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>
# activate the ncl environment<br>
conda activate ncl_stable<br>
<br>
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>
</font></font><font face="TeX Gyre Adventor"><font face="TeX
Gyre Adventor"><font face="TeX Gyre Adventor"><font face="TeX
Gyre Adventor">end shell script </font></font>-------------------------------<br>
</font></font></p>
<p><font face="TeX Gyre Adventor">Best fishes</font></p>
<p><font face="TeX Gyre Adventor">Sam<br>
</font></p>
<div class="moz-signature">-- <br>
<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" moz-do-not-send="true">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.9D4833F7.34CBC0CE@fishocean.info" class=""><br>
<br>
"The time has come", the tui said,<br>
"to talk of many things:<br>
Of songs - and ferns - and flowering flax,<br>
of pukekos and dreams ..."<br>
<br>
(not Lewis Carroll) </div>
</body>
</html>