一、本机脚本(基于mac)
#!/bin/sh
if [ $# -lt 1 ]; then
echo "deploy.sh <version number>"
exit 0
fi
cd /Volumes/z-vm-svn/Work/WebProjectName/WebRoot
zip -r WebProjectName.zip .
auto_scp_mzip(){
expect -c "set timeout -1;
spawn scp WebProjectName.zip root@192.168.1.38:/tmp;
expect {
*(yes/no)* {send yes\r;exp_continue;}
*assword:* {send passwordxxx\r;exp_continue;}
eof {exit 0;}
}";
}
auto_scp_mzip
#执行测试环境脚本
auto_ssh_exec(){
expect -c "set timeout -1;
spawn ssh root@192.168.1.38 ~/test138.sh $1 2>&1
expect {
*(yes/no)* {send yes\r;exp_continue;}
*assword:* {send passwordxxx\r;exp_continue;}
eof {exit 0;}
}";
}
auto_ssh_exec $1
二、测试环境脚本test138.sh(按需修改)
#!/bin/bash
if [ $# -lt 1 ]; then
echo "test138.sh <version number>"
exit 0
fi
cd /data/WebProjectName
#备份
time=$(date +%Y%m%d%H%M%S)
cmd_mk=$(mkdir -p ~/WebProjectName/m_$time)
echo $cmd_mk
cmd_cp=$(cp -r m/ ~/WebProjectName/m_$time)
echo $cmd_cp
rm -rf WebProjectName/ WebProjectName.zip
#更新
cp /tmp/WebProjectName.zip .
unzip WebProjectName.zip >>/tmp/WebProjectName_update.log
#版本修改
sed -i 's/_sysVersion = \"1.0...\"/_sysVersion = \"1.1.'$1'\"/g' index.html
echo "Version value is $1"
三、调用脚本
./deploy.sh 20190715001