2

I am trying to write a bash-script to update a remote git repo. The script looks something like:

#!/bin/bash
ssh user@remote.de 'cd /home/h/usr/praktikum  | git pull | sbatch run.sh'

However, the cd command has no effect!

fatal: not a git repository (or any parent up to mount point /home)

How can I get into the git folder: /home/h/usr/praktikum to run my git commands?

  • 3
    Why are you piping | the outputs of the commands into each other? Could it be that you accidentally used | instead of &&? – AdminBee Dec 2 '19 at 14:39
0

This works to me:

ssh user@remote.de -t "cd /home/h/usr/praktikum && git pull && sbatch run.sh; bash --login"

For not will leave you in a remote shell:

ssh user@remote.de -t "cd /home/h/usr/praktikum && git pull && sbatch run.sh"
3

Pipes (|) are used for connecting inputs and outputs of several command together in a pipeline. The commands run independently and concurrently with each other, apart from when they are waiting for input to appear or for output to be read. This is why the cd does not affect the current directory of the gitand sbatch commands. You don't want to use a pipeline here.

What you want to do is

ssh user@remote.de 'cd /home/h/usr/praktikum && { git pull; sbatch run.sh; }'

What this would do is to cd to the specified directory, and if that went well (the directory exists and you have permissions to access it), the git and sbatch commands are run.

In the command above, sbatch would run regardless of the exit status of git pull. If you want to avoid running sbatch if gitfor some reason fails, use

ssh user@remote.de 'cd /home/h/usr/praktikum && git pull && sbatch run.sh'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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