- 论坛徽章:
- 0
|
./deploy_test.sh test ico.zip
脚本如下:
#!/bin/bash
#下载文件 本地保存路径
localdir=/home/test/deploy/src/
wget -c -N -T 10 $2 -O $localdir$2||exit 1
#远端备份目录
backupdir=/opt/backup
#test
test=(23
#m
m=192.168.16.
case $1 in
test)
for ip in ${test[*]}
do
#echo $ip
scp -P22 $localdir$2 $m$ip:/tmp
ssh -p22 -t $m$ip<<EOF
#test远端存储目录
testdes=/opt/vhosts/test
#test远端程序目录
testdesdir_list=`ls /opt/vhosts/ | grep test`
#备份目录
backupdir=/opt/backup
if [ ! -d $backupdir ]
then
mkdir -p $backupdir && chown -R test:test $backupdir && chmod 775 $backupdir
fi
#提取所有test进程的id
testid_list=`ps aux|grep test | grep -v grep|awk '{print $2}'`
#提取所有test的tomcat进程的路径,必须tomcat名字都有OA,否则无法过滤
testtomcatdir_list=`ps aux|grep test | grep -v grep | awk '{print $12}'| sed -e 's/.*=\(.*\)\/conf.*/\1/g'`
for testid in $testid_list
do
kill -9 $testid
done
mv $testdes/ROOT.war $backupdir/ROOT.war.`date +%Y%m%d-%T`
for testdesdir in $testtomcatdir_list; do
mv /tmp/$2 $testdesdir/ROOT.war
rm -rf $testdesdir/ROOT
done
for testtomcatdir in $testtomcatdir_list
do
rm -rf $testtomcatdir/work/Catalina
sh $testtomcatdir/bin/startup.sh && echo update ok
done
source /etc/profile
exit 0
EOF
done
;;
esac
执行结果:
Address 192.168.16.238 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
ico.zip 100% 5358KB 5.2MB/s 00:00
+ ssh -p22 -t 192.168.16.238
++ ls /opt/vhosts/
++ grep test
++ ps aux
++ grep test
++ grep -v grep
++ awk '{print $2}'
++ ps aux
++ grep -v grep
++ grep test
++ awk '{print $12}'
++ sed -e 's/.*=\(.*\)\/conf.*/\1/g'
++ date +%Y%m%d-%T
Pseudo-terminal will not be allocated because stdin is not a terminal.
Address 192.168.16.238 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
-bash: line 13: 28572: command not found
-bash: line 14: 28576: command not found
-bash: line 18: -x: command not found
-bash: line 19: -x: command not found
...
...
也就是从获取pid进程的时候,就出错了,错误当中显示的两个id也不是正确的, testid_list=`ps aux|grep test | grep -v grep|awk '{print $2}'` 命令在远程主机16.238上执行完全没有问题,求指教~~~为什么
|
|