When I can't figure out WTF is going on with a shell script, I put something like this in the front of it:

/usr/bin/env > /tmp/this-is-my-environment

No matter how screwed up your env, path, choice of shell, output redirection, etc are, that's pretty much guaranteed to dump some useful information into someplace where you can find it.  The likely suspects are $SHELL, $PATH, $PWD, $USER.

In truly bizarre cases, there might be some permission problem, which you can solve with:

touch /tmp/this-is-my-environment
chmod 0666 /tmp/this-is-my-environment


On Nov 12, 2021, at 10:21 AM, YiFei Zhu <zhuyifei1999@gmail.com> wrote:

On Thu, Nov 11, 2021 at 3:57 PM Huji Lee <huji.huji@gmail.com> wrote:

Hi all,

Starting Nov 7, a number of the jobs I would run through Toolforge grid have stopped working. Each job consists of a .sh file like this on the first line of which I use the source command to activate a python virtual environment. When I run source by hand, subsequent lines work. But when I call the .sh file and it tries to run the source command, I get a "source: not found" message,

How are you calling the .sh file? It doesn't have a shebang so I'm
guessing you are doing
 $ sh daily.sh
In that case, invoke it with `bash`/ `zsh` instead of `sh`, since `sh`
is dash which does not have the not have the source command.
Alternatively you can use a dot instead of `source` which actually is
part of POSIX [1] and is implemented in dash,

`source` is also a zsh builtin [2] so I have no idea how it's breaking
for you. Somehow your scripts are being run by dash if you have `exec
zsh`, but since I don't know how you are invoking the scripts I cannot
trace the code.

YiFei Zhu

[1] https://man7.org/linux/man-pages/man1/dot.1p.html
[2] https://sourceforge.net/p/zsh/code/ci/master/tree/Src/builtin.c#l116

the virtual environment does not get activated and indeed running which python returns /usr/bin/python which is bad. All my scripts depend on pip packages that are installed in the virtual env and not available with the system python.

The main thing I did on Nov 7 was to add a line at the end of my too's account's .bash_profile as below:

exec zsh

This is because when I manually log into toolforge, I would like zsh to be my shell, and since tool accounts don't support chsh, I thought executing zsh directly from bash would be okay. But apparently, that now breaks the source command somehow.

So I wonder:

(a) Is there a way to properly change the default shell of tool accounts?
(b) Is there a way to make source work under zsh?

Importantly, I know the problem is with exec zsh because once I removed it and logged out and back in, all scripts worked correctly.

Thanks,
Huji
_______________________________________________
Cloud mailing list -- cloud@lists.wikimedia.org
List information: https://lists.wikimedia.org/postorius/lists/cloud.lists.wikimedia.org/
_______________________________________________
Cloud mailing list -- cloud@lists.wikimedia.org
List information: https://lists.wikimedia.org/postorius/lists/cloud.lists.wikimedia.org/