用于 git fetch 和 rebase的 bash 脚本



我正在尝试通过构建脚本来自动化与 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 将读取其 stdin 以运行命令。您可以使用 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"

它将连接实例并从那里运行这些命令。

最新更新