一、Linux
- sshpass
1.1 修改 deploy.sh 中的配置信息
1.2 执行 deploy.sh
#!/bin/bash
echo "One key to deploy, by xxx."
# =========================== >>>基于 sshpass>>> =================================
# 下载地址: https://sourceforge.net/projects/sshpass/
# =========================== <<<基于 sshpass<<< =================================
# =========================== >>>配置信息>>> =================================
# 服务器连接信息
server="xxx"
username="xxx"
password="xxx"
# 远程目录路径
remote_dir="/tmp/web"
# 远程 zip 文件路径
remote_file="${remote_dir}/a.zip"
# 远程 zip 文件解压路径
remote_unzip_dir="${remote_dir}/a"
# 本地 zip 文件路径
local_file="a.zip"
# =========================== <<<配置信息<<< =================================
# 登录服务器并上传本地文件
echo "1. Uploading local file to server..."
sshpass -p "${password}" scp "${local_file}" "${username}@${server}:${remote_file}"
# 删除服务器上已有的目录
echo "2. Deleting existing directory on server..."
sshpass -p "${password}" ssh "${username}@${server}" "rm -rf ${remote_unzip_dir}"
# 解压服务器上的 zip 文件
echo "3. Extracting remote file to directory..."
sshpass -p "${password}" ssh "${username}@${server}" "unzip -o ${remote_file} -d ${remote_unzip_dir}"
echo "Done."
二、Windows
- putty
1.1 下载并安装 putty,地址 https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
1.2 修改 deploy.bat 中的配置信息
1.3 执行 deploy.bat
@echo off
echo One key to deploy, by xxx.
REM =========================== >>>基于 PUTTY>>> =================================
REM 下载地址: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
REM =========================== <<<基于 PUTTY<<< =================================
REM =========================== >>>配置信息>>> =================================
REM 服务器连接信息
set server=xxx
set username=xxx
set password=xxx
REM 远程目录路径
set remote_dir=/tmp/web
REM 远程 zip 文件路径
set remote_file=%remote_dir%/a.zip
REM 远程 zip 文件解压路径
set remote_unzip_dir=%remote_dir%/a
REM 本地 zip 文件路径
set local_file=a.zip
REM =========================== <<<配置信息<<< =================================
REM 登录服务器并上传本地文件
echo 1. Uploading local file to server...
echo | plink -ssh -pw %password% %username%@%server% "mkdir -p %remote_dir%"
echo | pscp -scp -pw %password% %local_file% %username%@%server%:%remote_file%
REM 删除服务器上已有的目录
echo 2. Deleting existing directory on server...
echo | plink -ssh -pw %password% %username%@%server% "rm -rf %remote_unzip_dir%"
REM 解压服务器上的 zip 文件
echo 3. Extracting remote file to directory...
echo | plink -ssh -pw %password% %username%@%server% "unzip -o %remote_file% -d %remote_unzip_dir%"
echo Done.
pause
- ssh - 推荐
2.1 基于定制化的 open ssh,添加了 -Z 参数,用于提供密码,地址 https://github.com/dkrahmer/openssh-portable
2.2 修改 deploy.sh 中的配置信息
2.3 在 git bash 中执行 deploy.sh
2.4 也可以基于此定制化的 ssh 使用 bat 脚本执行
#!/bin/bash
echo "One key to deploy, by xxx."
# =========================== >>>基于 git+openssh>>> =================================
# 下载地址: https://github.com/dkrahmer/openssh-portable
# =========================== <<<基于 git+openssh<<< =================================
# =========================== >>>配置信息>>> =================================
# 服务器连接信息
server="xxx"
username="xxx"
password="xxx"
# 远程目录路径
remote_dir="/tmp/web"
# 远程 zip 文件路径
remote_file="${remote_dir}/a.zip"
# 远程 zip 文件解压路径
remote_unzip_dir="${remote_dir}/a"
# 本地 zip 文件路径
local_file="a.zip"
# =========================== <<<配置信息<<< =================================
# 登录服务器并上传本地文件
echo "1. Uploading local file to server..."
./scp.exe -Z "${password}" "${local_file}" "${username}@${server}:${remote_file}"
# 删除服务器上已有的目录
echo "2. Deleting existing directory on server..."
./ssh.exe -Z "${password}" "${username}@${server}" "rm -rf ${remote_unzip_dir}"
# 解压服务器上的 zip 文件
echo "3. Extracting remote file to directory..."
./ssh.exe -Z "${password}" "${username}@${server}" "unzip -o ${remote_file} -d ${remote_unzip_dir}"
echo "Done."
网友评论