Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Is there any way that ssh can specify the working directory on the remote host when executing bash scripts through ssh? So that the bash scripts can use relative path in it instead of absolute path. The below example seems not working. Please help, thanks.

Example for bash script on remote host:

./executable -o arg1 -i arg2

Example for command send on local:

ssh id@remote.hostname '/path/to/script/myscript.sh'
share|improve this question

1 Answer 1

up vote 5 down vote accepted

Your working directory on the target system should be the login users's home directory. run

 ssh id@server pwd

If you want to be in a particular directory before running the program, then do this:

 ssh id@server "cd /path/to/dir && pwd"

Do note the double quotes, without quotes, it will get treated as two commands.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.