数据库和JDK安装检测脚本

对于自动化的脚本,一般需要首先检查应用软件是否安装,这里作为一个范例显示数据库和JDK的安装检测  
#!/usr/bin/env bash 
#===============================================================================
#
#          FILE: check_env.sh
# 
#         USAGE: ./check_env.sh 
#   DESCRIPTION: Detection database and jdk installed
#       OPTIONS: ---
#  REQUIREMENTS: ---
#         NOTES: ---
#        AUTHOR: Eric Wu, [email protected]
#       CREATED: 05/12/2014 15:37
#      REVISION:  ---
#===============================================================================
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

[ ! -d $DDIR ] && mkdir -p /opt/ddir

function echo_e (){
# echo error
    echo -en "\033[31m\033[1m$1\033[0m\n" | tee -a $uploadlog
}

function echo_o (){
# echo ok
    echo -en "\033[32m\033[1m$1\033[0m\n" | tee -a $uploadlog
}

function check_install(){
    [ ! -d $SDIR ] && { echo -e "\033[;31m No such directory found : $SDIR ! \033[0m"; exit; }
}

function check_mysql(){
        MYSQLPATH="/usr/local/mysql/data/mysql"
        CMDCHECK=`lsof -i:3306 &>/dev/null` 
        MYSQLPort="$?"
        PIDCHECK=`ps aux|grep mysqld|grep -v grep` 
        MYSQLPID="$?"
        if [ -d $MYSQLPATH -a "$MYSQLPort" -eq "0" -a "$MYSQLPID" -eq 0 ];then
                echo_o "MYSQL is installed !!!"
        else
                echo_e "Error:MYSQL is not installed !!!"
        fi
}

function check_jdk(){
        CMDCHECK=`java -version 2&>1 /dev/null`
        JDKSVR="$?"
        CMDENV=`more /etc/profile| grep JAVA_HOME`
        JDKENV="$?"
        if [ "$JDKSVR" -eq 0 ];then
                echo_o "JDK is installed !!!"
        else
                echo_e "Error:JDK is not installed !!!"
        fi
        if [ "$JDKENV" -eq 0 ];then
                echo_o "JDK (/etc/profile) is ready !!!"
        else
                echo_e "JDK (/etc/profile) is not ready !!!"
        fi
}

check_mysql
check_jdk

你可能感兴趣的:(数据库和JDK安装检测脚本)