当我在我的开发服务器上部署时,我使用 rsync。但是在 rsync 之后,我需要为“之后”部署操作(如清除缓存)执行一个 .sh 文件......
通常我通过 SSH 执行此操作,但如果我经常部署它会很无聊:
- 嘘...
- 写密码
- cd /var/www/myapp/web
- ./after_deploy.sh
有没有办法快速做到这一点?这是我的 rsync.sh:
#!/bin/bash
host=""
directory="/var/www/myapp/web"
password=""
usage(){
echo "Cant do rsync";
echo "Using:";
echo " $0 direct";
echo "Or:";
echo " $0 dry";
}
echo "Host: $host";
echo "Directory: $directory"
if [ $# -eq 1 ]; then
if [ "$1" == "dry" ]; then
echo "DRY-RUN mode";
rsync -CvzrltD --force --delete --exclude-from="app/config/rsync_exclude.txt" -e "sshpass -p '$password' ssh -p22" ./ $host:$directory --dry-run
elif [ "$1" == "direct" ]; then
echo "Normal mode";
rsync -CvzrltD --force --delete --exclude-from="app/config/rsync_exclude.txt" -e "sshpass -p '$password' ssh -p22" ./ $host:$directory
else
usage;
fi;
else
usage;
fi