2

I am trying to automate a few steps that I need to execute in a remote linux machine from my local ubuntu computer.

My shell script is as follows :-

#!/bin/sh

ssh XYZ '

qlogin -l cuda=1

'

When I am trying to execute it by collecting the ./fileName.sh . I am getting

bash: line 2: qlogin: command not found

However, when I do it manually i.e. ssh into the cluster and than run this command , I am able to execute it.

Troubleshooting till now

  1. Both the local and remote terminal is bash . This I got by echo $0

  2. When I manually ssh into the remote and print the path for qlogin (via which qlogin). I get

/opt/ge/bin/lx-amd64/qlogin

However, when I do the same via the script,I don't get any which means that qlogin is not installed.

  1. Finally, I the user executing the script and the user that logs in when i manually ssh are not the same (got it by printing the who).

What should I do ?

1 Answer 1

0

What you'd want in this case is:

ssh XYZ "qlogin -l cuda=1"

or

ssh XYZ "export TERM=xterm ; qlogin -l cuda=1"

In case you get some error about the TERM variable not being set, or:

ssh XYZ << 'EOF'
qlogin -l cuda=1
EOF

If you have multiple command to run.

Lastly, since I'm sure that this could work if the above don't:

ssh XYZ << 'EOF'
shopt -s expand_aliases
source .bashrc
qlogin -l cuda=1
EOF

As you probably noticed, the last one may work if the other one don't, mainly if qlogin isn't in one of the default exported PATH, and is either:

  • aliased somewhere else (eg: some remote servers like to keep their install script in a mounted NFS folder that isn't exported in PATH)

  • if it's part of a larger function/script made of functions.

You could look at the output of env, alias and whereis to make sure of that. Replacing .bashrc with anything else that may mention the full path of the qlogin command, such as .profile or other ones come to mind.

5
  • It didnot work.
    – Echo
    Mar 24, 2021 at 15:56
  • what was the error? see the edit i made in case this work for you. Mar 24, 2021 at 15:58
  • maybe try to use the full path for the command instead: /opt/ge/bin/lx-amd64/qlogin in the example above @Echo Mar 24, 2021 at 15:59
  • 1
    Hi, I did something similar . ssh XYZ ' source /opt/ge/default/common/settings.sh && qlogin -l cuda=1 ' This helped. The issue was with login session as doing it via ssh script leads to a non login session and that caused the issue.
    – Echo
    Mar 24, 2021 at 16:38
  • yeah, that's why i mentioned the last one, because i thought it might be an alias or script that was sourced somewhere :) glad it's fixed @Echo Mar 24, 2021 at 17:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .