Bash – Screen cannot exec ‘Myscript.sh’: No such file or directory

bashbashrcgnu-screenssh

I am trying to execute a script on a remote machine in screen session using ssh. The command I use is:

ssh -t MYSERVER "cd tempdirXYZ; screen Myscript.sh"

When I execute this, I see a screen window for a few seconds displaying

cannot exec 'Myscript.sh': No such file or directory

I use bash on the remote machine and the script is placed in my ~/bin folder. It seems that when I run the above command, my bash files are not being sourced. I am not even sure if bash is run at all.

Is there any way to make this work without changing the command? The remote machine is running Ubuntu.

Best Answer

I just realised you said ~/bin and not /bin.

You need to execute the following to add the directory to the system's PATH variable:

export PATH=\$PATH:/home/<username>/bin

This should allow you to run the script as above. If not it's likely not marked as executable so run:

chmod +x ~/bin/Myscript.sh
Related Question