linux shell测试脚本

#!/bin/sh

 
#=============================================================#
# Start_all_system_services.sh #
# Modified By Hu Changwen on july 13th 2009 #
# [email protected] && 1581339**** #
# D&A Technology Co., Ltd. Guangzhou Technology Support Center # #
#=============================================================#
#Define the install path of all the services

 
MYSQL_PATH=/usr/local/mysql
OPENLDAP_PATH=/usr/local/openldap
POSTFIX_PATH=/usr/local/postfix

 
#=======================================================================#
#Define the mysql start function
mysql_start() {
mysql_start_result=`$MYSQL_PATH/bin/mysql.server start`
sleep 3
mysql_start_result_err=`netstat -nutlp | grep mysqld | grep 3306`
[ -z "$mysql_start_result_err" ] && mysql_error "$mysql_start_result" || echo -e " [ \033[32;1mOK\033[32;0m ]"

 
}

 
#Define the mysql error function
mysql_error() {
echo -e " [ \033[31;1mNG\033[31;0m ]"
echo "$1"

 
}

 
#Define the main mysql start function
mysql() {
echo -ne "Starting Mysql Service..."

 
mysql_running=`netstat -nutlp | grep mysqld | grep 3306`

 
[ -z "$mysql_running" ] && mysql_start || mysql_error "Mysql Service is running!"

 
}

 
#=============================================================================#
#Openldap Service Start Shell
#Define the openldap service start function

 
openldap_start() {
openldap_start_result=`$OPENLDAP_PATH/libexec/slapd &`
sleep 3
openldap_start_result_err=`netstat -nutlp | grep slapd | grep 389`
[ -z "$openldap_start_result_err" ] && openldap_error "$openldap_start_result" || echo -e " [ \033[32;1mOK\033[32;0m ]"
 
}

 
openldap_error() {
 
echo -e " [ \033[31;1mNG\033[31;0m ]"
echo "$1"

 
}

 
openldap() {
echo -ne "Starting Openldap Service..."
 
openldap_running=`netstat -nutlp | grep slapd | grep 389`

 
[ -z "$openldap_running" ] && openldap_start || openldap_error "Openldap Service is running!"

 
}
#============================================================================#

 
postfix_start() {
postfix_start_result=`$POSTFIX_PATH/usr/sbin/postfix start`
sleep 3
postfix_start_result_err=`netstat -nutlp | grep master | grep 25`
[ -z "$postfix_start_result_err" ] && postfix_error "$postfix_start_result" || echo -e " [ \033[32;1mOK\033[32;0m ]"

 
 
}

 
postfix_error() {
 
echo -e " [ \033[31;1mNG\033[31;0m ]"
echo "$1"

 
}

 
postfix() {
echo "Starting Postfix Service..."
 
postfix_running=`netstat -nutlp | grep master | grep 25`

 
[ -z "$postfix_running" ] && postfix_start || postfix_error "Postfix Service is running!"

 
}

 
#===========================================================================#
#Main shell

 
mysql
openldap
postfix

 

你可能感兴趣的:(linux,mysql,shell,postfix,休闲)