1. 安装homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2. 将SSH KEY公钥添加到Linux服务器
方法一:
brew install ssh-copy-id
ssh-copy-id -i ~/.ssh/id_rsa.pub root@Linux服务器IP
方法二:
获取公钥,cat ~/.ssh/id_rsa.pub
然后在Linux服务器上,编辑文件 vim ~/.ssh/authorized_keys,将公钥添加进去并保存
3. 安装fswatch
brew install fswatch
4. 配置自动上传脚本
sudo vim /mac-auto-deploy (注: 文件所在目录可自定义)
输入下在的内容:
#======
#!/bin/sh
local=$1
remote=$2
cd "$local" &&
fswatch . |xargs -n1 -I{} rsync -aztH --exclude .git --exclude .sass-cache --exclude .idea --delete --progress --rsh='ssh -l root -p22' . $remote
#======
5. 执行自动上传脚本
cd /xxx/xxx,进入本地项目根目录,
执行 /mac-auto-deploy . root@Linux服务器IP:Linux服务器项目路径(注:mac-auto-deploy文件需要给执行权限;当检测有文件变化时,就会开始上传文件)