-1

There is the following bash script:

#!/bin/bash

set -o errexit

# Общие параметры
server="some_server"
login="admin"
default_path="/home/admin/web/"
html_folder="/public_html"

# Параметры проекта
project_folder="project_name"

go_to_folder() {
  ssh "$login@$server"
  cd "/home/admin/web/"
}

go_to_folder

I got error "deploy.sh: line 16: cd: /home/admin/web/: No such file or directory", but if I connect manually and change directory through "cd" it works. How can I change my script?

malcoauri
  • 10,195
  • 24
  • 72
  • 124

1 Answers1

0

Yes it is obvious, didn't it? You are trying to do cd to the local machine and not on the target machine. The commands to be passed to ssh much be provided in-line with its parameters, on a separate newline its looking as if you are doing no-op on the remote machine and running the cd in the local.

go_to_folder() {
ssh "$login@$server" "cd /home/admin/web/"      
}

Or a more cleaner way to do would be to use here-docs

go_to_folder() {
ssh "$login@$server" <<EOF
cd /home/admin/web/
EOF
}

other ways to make ssh read from stanard input on the commands to run would be to use here-strings(<<<) also.

Inian
  • 62,560
  • 7
  • 92
  • 110