服务器关闭、启动服务脚本

shutdown.sh

dir=/server/
jarfile=app.jar
TARGET=$dir$jarfile

pid=$(ps -ef | grep $TARGET | grep -v grep | awk '{print $2}')
if [ "x$pid" != "x" ]; then
        kill $pid

        for i in {1..30}; do
                sleep 1
                echo -n .

                pid=$(ps -ef | grep $TARGET | grep -v grep | awk '{print $2}')
                if [ "x$pid" == "x" ]; then
                        echo success
                        exit 0
                fi
        done

        echo failed
        exit 1
fi

echo success

start.sh

dir=/server/
backFolder=bak/
jarfile=app.jar
echo "start server..."
nohup java -Xmx1024m -Xms256m -jar $dir$jarfile >/dev/null  2>&1 &

if [ ! -d $dir$backFolder ];then
  echo "创建备份文件夹"
  mkdir $dir$backFolder
else
  echo "备份文件夹存在"
fi
echo "start server over"
echo "check jarfile is backed up"
lastBackName=$(ls -lt $dir$backFolder | awk '{print $9}' | sed -n '2p')
echo $lastBackName
backuped=false

if [ -z "$lastBackName"  ]; then
    echo "jar file is never backed up"
else
    diffStr=$(diff -a $dir$backFolder$lastBackName  $dir$jarfile)
    if [ -z "$diffStr" ]; then
        backuped=true
        echo "jarfile has been backed up.fileName:"$dir$backFolder$lastBackName
    else
        echo "jarfile not back up"
    fi
fi

if ! $backuped ; then
    echo "jarfile start back up..."
    nowtime=$(date "+%Y%m%d%H%M%S")
    cp $dir$jarfile  $dir$backFolder$nowtime.jar
    echo "jarfile backed up"
fi

bak为备份文件夹,启动时检查bak下最新的jar文件和当前启动jar文件是否一样,如果不一样将当前jar文件拷贝到bak文件夹下,并重命名为当前时间

批量kill进程

ps aux|grep google-chrome|awk '{print $2}'|xargs kill -9

ps aux|grep webdriver|awk '{print $2}'|xargs kill -9

查看cpu 内存占用

top

快捷键排序:shift+c shift+m

根据pid查看对应进程

ps -aux |grep -v grep|grep PID_NUM
发表新评论