Dobflem
Posts: 2
Joined: Tue Jul 29, 2014 10:27 am

Connect through ssh and execute command

Tue Jul 29, 2014 10:34 am

Hi,

I've set up my pi so that I can connect without a password. (id_rsa.pub)

I would like to write a batch script that simply:

ssh pi@10.10.10.73
cd ~/gitRepos/MyRepo
git pull

Any ideas on how to do this?

Note: I have tried this in a .sh file:

ssh pi@10.10.10.73 <<'ENDSSH'
cd ~/gitRepos/MyRepo
git pull
ENDSSH


And here is my output:

Pseudo-terminal will not be allocated because stdin is not a terminal.
Linux rasbpi 3.12.22+ #691 PREEMPT Wed Jun 18 18:29:58 BST 2014 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
fatal: /usr/lib/git-core/git-pull cannot be used without a working tree.


Note: When I log in to the pi and use "git pull" it works fine.

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: Connect through ssh and execute command

Tue Jul 29, 2014 1:49 pm

Code: Select all

ssh pi@10.10.10.73 'cd ~/gitRepos/MyRepo && git pull'
Basically it ssh into the pi and executes what is in the quotes. It cd into the directory, the && says to execute another command and then pulls from git.
There are 10 types of people: those who understand binary and those who don't.

Return to “Beginners”