- #!/bin/bash
- #File: open***_turn
- #Auth: Robin
- #Date: 2013/01/17 10-30-10
- #Desc: Start/stop open*** client
- #Vers: 1.0
- #
- # open*** -s --> stop open*** client
- # open*** -r --> start open*** client
- #配置文件所在目录
- CONF_DIR="/etc/open***"
- #配置文件
- CONF_FILE="client.conf"
- #存放用户名和密码,格式如下
- # user_name
- # password
- AUTH_FILE="auth"
- LOG_FILE="/tmp/open***.log"
- PID_FILE="/tmp/open***.pid"
- function do_success {
- ps -ef|grep open***|grep -v grep|awk '{print $2}' >> $PID_FILE
- rm $LOG_FILE
- echo -e "Start OPEN××× \033[32msuccessfully\033[0m!"
- exit 0
- }
- function do_fail {
- echo -e "Start OPEN××× \033[41mfailure\033[0m!"
- echo "Maybe you can get something useful from $LOG_FILE"
- exit 1
- }
- function if_run {
- if [ -e $PID_FILE ];then
- return 0
- else
- return 1
- fi
- }
- function start_open*** {
- if_run
- if [ $? -eq 0 ];then
- ps -ef|grep '\<open***\>' |grep -v grep &> /dev/null
- if [ $? -eq 0 ];then
- echo -e "OPEN××× is \033[32malready running\033[0m!!!"
- exit 1
- else
- rm $PID_FILE
- fi
- fi
- if [ -e $LOG_FILE ];then
- echo > $LOG_FILE
- fi
- cd $CONF_DIR
- sudo open*** --config $CONF_FILE --auth-user-pass $AUTH_FILE &> $LOG_FILE &
- echo -e "\033[33mStarting\033[0m OPEN×××..."
- sleep 5
- cat $LOG_FILE |grep "Sequence Completed" 2> /dev/null && do_success || do_fail
- }
- function stop_open*** {
- if_run
- if [ $? -eq 1 ];then
- echo "OPEN××× is not running!"
- exit 1
- fi
- for i in `ps -ef|grep '\<open***\>'|grep -v grep|awk '{print $2}'`;do
- sudo kill -9 $i
- done
- rm $PID_FILE
- echo -e "OPEN××× is already \033[41mstop\033[0m."
- }
- while getopts sr SW;do
- case $SW in
- s)
- stop_open***
- break
- ;;
- r)
- start_open***
- break
- ;;
- ?)
- echo "open***_turn [s|r]"
- esac
- done
转载于:https://blog.51cto.com/ouroboros/1120547