How do I write shell scripts in linux to publish code on a remote server at the local key?

  question

As a result of data loss caused by server misoperation of gitlat some time ago, I deeply felt the risk of typing commands directly on the server, so I want to minimize the number of times I board the server, thus leading to this problem.

Scene: Now I publish the code of the server directly to the server and then run the publish.sh file to complete the release of the new code. How can I transfer this operation to my local system OS X?

My idea is to write a script file and then connect the ssh command to the server. However, there is a problem. Normally, after ssh is connected, there is an interactive interface. What I want to complete is to directly publish the project as: /usr/local/publish xxx. But I didn’t see a command to fulfill similar requirements in the shell.

And I still have a question, how can I directly perform an operation (query/update/add) on the online database locally? Because online databases usually have security IP verification, so it is usually only possible to directly log on to the server to type sql commands, but this is also a risky operation. If you accidentally delete from table, it is not so good (although there is a hot recovery data tool). How can you operate the database in a safer way by script transfer (or the like)?

This is our favorite script for simple deployment:

function run_script() {
 ssh -i ${SSH_CERT} -p 22 ${REMOTE_USER}@${REMOTE_HOST} "$@"
 return $?
 bracket
 
 function upload_file() {
 scp -i ${SSH_CERT} -P 22 "$1" ${REMOTE_USER}@${REMOTE_HOST}:"$2"
 return $?
 bracket
 
 function upload_dir() {
 scp -i ${SSH_CERT} -P 22 -r "$1" ${REMOTE_USER}@${REMOTE_HOST}:"$2"
 return $?
 bracket
 
 Upload_file "local file path" "remote file path" || exit 1
 Upload_dir "local directory path" "remote parent directory path under which the directory will reside" || exit 1
 Run_script "execute script remotely" || exit 1