0

I have a deploy.sh file that I would like to run from my local macbook that will ssh into a remote Ubuntu 22 server and run a few commands there. Example here:

#!/opt/homebrew/bin/zsh

main() {
  scp \
    on_server.sh \
    # other files \ 
    "$remote_location:/correct/location"

  ssh $remote_location "cd correct/location; echo $SHELL; ./on_server.sh"
}

main "$@"

The on_server.sh file has a couple commands using pnpm and pm2:

#!/usr/bin/zsh

pnpm i
pnpm build

pm2 restart app_name

If I ssh manually into my server, cd into the right place, and run those pnpm & pm2 commands everything is fine. When my deploy.sh does seemingly the same thing, I get errors that pnpm and pm2 commands are not defined.

However, I noticed that $SHELL is different between the two situations.

Manual ssh:

ssh <remote_location>
...
echo $SHELL
/usr/bin/zsh

The output of the echo $SHELL from on_server.sh above is:

/bin/zsh

I believe this $SHELL difference is why my commands are failing. Can someone help me understand why there is this difference in the $SHELL value?

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
Jackson H
  • 65
  • 3
  • 6
  • `$SHELL` is expanded *locally* before `ssh` even executes. If you want the value of `$SHELL` on the remote host, use single quotes: `ssh $remote_location 'cd ...; echo $SHELL; ./on_server.sh'`. – chepner Jul 07 '23 at 19:54
  • Yes, that does actually, thanks. Changing to single quotes gets the same $SHELL value. I'll make an edit to my question to make that clear. – Jackson H Jul 07 '23 at 20:01
  • `/correct/location` and `correct/location` are two different directories, unless you are logging in as a user that has `/` as its home directory. – chepner Jul 07 '23 at 20:10
  • 1
    Please dont edit your question into a different one. Thats not how this site works. Ask a new question with your new problem. I have rolled it back. – Rohit Gupta Jul 09 '23 at 10:46
  • I'm not aware of a **reliable** way a zsh script can find out the path of the zsh-executable which is running the script. `SHELL` certainly is not necessarily correct, as this is just a variable anyone can change. Why is the location of the executable of importance? If you want to find differences in the zsh variants, I would query the variable `ZSH_VERSION`. This at least is set by zsh itself on startup. – user1934428 Jul 12 '23 at 11:42
  • Even if you know that the PATH to zsh is the same on both hosts, this does not tell you that in both cases you are running the same zsh version.... – user1934428 Jul 12 '23 at 11:46

0 Answers0