#!/bin/bash ## Usage # 如果虚机上的shell里面不能执行sudu,这个脚本就能派上用场,在root用户下执行此脚本,也就绕过sudo限制了 ## ./checkService.sh ztsjxxxt.jar "/usr/local/jar" ztsjxxxt "/home/ubuntu/" "production/investigate/backEnd/" fileName=$1 projectPath=$2 serviceName=$3 workDirectory=$4 ossPath=$5 PATH=PATH:/usr/bin:/usr/sbin function uploadLog () { echo "current user is ${USER}" journalctl -n 1000 -xe -t autoDeploy > ${workDirectory}autoDeploy.log ${workDirectory}ossutil cp ${workDirectory}autoDeploy.log oss://ztupload/${ossPath}autoDeploy.log if [ $? -ne 0 ]; then echo "error: upload log to oss failed!" exit 0 fi } cd $workDirectory echo "current path: $(pwd)" if [ ! -f "$fileName" ];then echo "文件 $fileName 不存在1!" exit 0 fi oriSum=$(md5sum $fileName) oriSum="${oriSum% *}" echo "origin file $fileName md5sum: $oriSum" if [ ! -d "$projectPath" ]; then echo "文件夹 $prjectPath 不存在!" exit 0 fi cd $projectPath desSum="" if [ ! -f "$fileName" ];then cp ~/$fileName . exit 0 else desSum=$(md5sum $fileName) desSum="${desSum% *}" echo "current path: $(pwd)" echo "destination file ${fileName} md5sum: ${desSum}" fi if [ ${oriSum} = ${desSum} ];then journalctl -n 1000 -xe -t autoDeploy > ${workDirectory}autoDeploy.log ${workDirectory}ossutil cp ${workDirectory}autoDeploy.log oss://ztupload/${ossPath}autoDeploy.log echo "destination file is same with origin file,no need to replace" uploadLog exit 0 fi systemctl restart $serviceName if [ $? -ne 0 ]; then echo "error: systemctl restart ${serviceName} failed!" exit 0 fi echo "ok: systemctl restart ${serviceName} success!" sleep 10 uploadLog