1. 程式人生 > >Linux-查詢對應的服務與JDK安裝

Linux-查詢對應的服務與JDK安裝

 查詢對應的服務並執行相關命令

 

#!/bin/bash
source ~/.bashrc
echo ">>>指令碼位置:$0"
echo ">>>任務引數:$1"
SERVER_NAME=test
if [ -n "$1" ]; then
 SERVER_NAME=$1
fi
echo "The serverName is $SERVER_NAME"
PIDS=$(ps -aux |grep home| grep $SERVER_NAME |awk '{print $2}')

## 是否查詢到對應的服務
if [ -n "$PIDS" ]
 then
    echo "The $SERVER_NAME $PIDS is running!"
    echo "killing..."
    sudo kill -9 $PIDS
    echo "The $SERVER_NAME $PIDS already killed!"
 else
    echo "The server $SERVER_NAME is not running"
fi

## 如果引數 SERVER_NAME 指定為"test"服務
if [ "$SERVER_NAME" == "test" ]; then
  sudo rm -rf /home/apps/test-server/
  sudo cp /home/test/test-server-release.tar.gz /home/apps/test-server-release.tar.gz
  sudo tar -xvf /home/apps/test-server-release.tar.gz -C /home/apps/
  ll /home/apps
  ## 切換work使用者,執行start.sh
  nohup sudo su - work -s /home/apps/test-server/bin/start.sh jmx >/home/test/nohup.out 2>&1 &
  tail -50f /data/logs/test/stdout.log
fi

JDK安裝

wget後加上 --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" 就可以了,如:

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.tar.gz