簡體   English   中英

用於git提取和重新設置的bash腳本

[英]bash script for git fetch and rebase

我正在嘗試通過構建腳本來自動化與Git的交互。

我想要

  1. 使用.pem文件連接亞馬遜實例

  2. 從該ubuntu實例運行git命令

我是shell編程的初學者。 我可以嘗試這樣做

#!/bin/bash
GIT_REPO='git_repo'
BRANCH='branch'
ssh -i ~/Downloads/4EBDBInstance.pem ubuntu@122.248.237.95
cd $GIT_REPO
git fetch -a
git checkout $BRANCH
git rebase origin/$BRANCH

我有一個錯誤

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/PATH/Instance_key.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: PATH/Instance_key.pem
Permission denied (publickey).  

實際上,我嘗試在bash文件中實現以下Unix命令

$sudo ssh -i PATH/instance_key.pem ubuntu@000.000.000.00
$cd git_repo
$git fetch -a
$git checkout master
$git rebase origin/master

(note:- need to inform with a message if any conflicts occurs and continue)

$sudo ssh -i PATH/instance_key.pem ubuntu@111.111.111.11
$cd git_repo
$git fetch -a
$git checkout release
$git rebase origin/release

(note:- need to inform with a message if any conflicts occurs)

實施任何幫助

ssh將讀取其標准輸入以運行命令。 您可以使用heredoc:

ssh -i ~/Downloads/4EBDBInstance.pem ubuntu@122.248.237.95 <<END
cd $GIT_REPO
git fetch -a
git checkout $BRANCH
git rebase origin/$BRANCH
END

為您的亞馬遜金鑰授予400權限,然后嘗試

GIT_REPO='git_repo'
BRANCH='branch'
ssh -i ~/Downloads/4EBDBInstance.pem ubuntu@122.248.237.95 "cd $GIT_REPO && git stash && git checkout $BRANCH && git fetch -a && git rebase origin/$BRANCH"

它將連接實例並從那里運行這些命令。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM