1

We have a server ( hosting ) and we need to git pull every morning by manually. We have tried to make it easier by a shell script file.

# /bin/bash

# add key
ssh-add /Users/ownner/Documents/keys/key.pem
# Access the server
ssh [email protected] -p18181
# Wait and type the password

# Each to check
echo "Hello, I am in the server now"

# Move to the folder
cd www/folder1/public_html/wp-content/plugins

# Git pull
find . -mindepth 1 -maxdepth 1 -type d -print -exec git -C {} pull \;

It works fine until adding the password. But it is not working after that. The less of code work when I "exit" ssh.

I believe I have missed something. FYI, We actually need to git pull on 6 folders. ( folder1, folder2, folder3, folder4, folder5, folder6 ). So we will use "for each" for the loop.

Can you please give us a tip how the cd, git pull work after login ( access ) the server?

Thank you,

1
  • Check man ssh. ssh foo@bar [command]. So you can append commands to the ssh-line. Commented Feb 18, 2021 at 8:03

1 Answer 1

1

Try and put the last three command in a script, in the remote server, in an interactive SSH session.

You can make that script as elaborate as you need, finding folders, and executing git pull on each one.
The point is: once the script work on the remote server, then you can call it with a non-interactive SSH call:

ssh [email protected] -p18181 /path/to/remote/script

Note: if you have a local public key.pub, you could copy it to the remote server ~myusername/.ssh/authorized_keys, and you would not have to enter the myusername password anymore.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.