1. #!/bin/bash 
  2. #File: open***_turn 
  3. #Auth: Robin 
  4. #Date: 2013/01/17 10-30-10 
  5. #Desc: Start/stop open*** client 
  6. #Vers: 1.0 
  7. # open*** -s --> stop open*** client 
  8. # open*** -r --> start open*** client 
  9.  
  10. #配置文件所在目录 
  11. CONF_DIR="/etc/open***" 
  12. #配置文件 
  13. CONF_FILE="client.conf" 
  14. #存放用户名和密码,格式如下 
  15. # user_name 
  16. password 
  17. AUTH_FILE="auth" 
  18. LOG_FILE="/tmp/open***.log" 
  19. PID_FILE="/tmp/open***.pid" 
  20.  
  21. function do_success { 
  22.     ps -ef|grep open***|grep -v grep|awk '{print $2}' >> $PID_FILE 
  23.     rm $LOG_FILE 
  24.     echo -e "Start OPEN××× \033[32msuccessfully\033[0m!" 
  25.     exit 0 
  26.  
  27. function do_fail { 
  28.     echo -e "Start OPEN××× \033[41mfailure\033[0m!" 
  29.     echo "Maybe you can get something useful from $LOG_FILE" 
  30.     exit 1 
  31.  
  32. function if_run { 
  33.     if [ -e $PID_FILE ];then 
  34.         return 0 
  35.     else 
  36.         return 1 
  37.     fi  
  38.  
  39. function start_open*** { 
  40.     if_run 
  41.     if [ $? -eq 0 ];then 
  42.         ps -ef|grep '\<open***\>' |grep -v grep &> /dev/null 
  43.         if [ $? -eq 0 ];then 
  44.             echo -e "OPEN××× is \033[32malready running\033[0m!!!" 
  45.             exit 1 
  46.         else 
  47.             rm $PID_FILE 
  48.         fi 
  49.     fi 
  50.      
  51.     if [ -e $LOG_FILE ];then 
  52.         echo > $LOG_FILE 
  53.     fi 
  54.  
  55.     cd $CONF_DIR 
  56.     sudo open*** --config $CONF_FILE --auth-user-pass $AUTH_FILE &> $LOG_FILE & 
  57.  
  58.     echo -e "\033[33mStarting\033[0m OPEN×××..." 
  59.     sleep 5 
  60.     cat $LOG_FILE |grep "Sequence Completed" 2> /dev/null && do_success || do_fail 
  61.  
  62. function stop_open*** { 
  63.     if_run 
  64.     if [ $? -eq 1 ];then 
  65.         echo "OPEN××× is not running!" 
  66.         exit 1 
  67.     fi 
  68.     for i in `ps -ef|grep '\<open***\>'|grep -v grep|awk '{print $2}'`;do 
  69.         sudo kill -9 $i 
  70.     done 
  71.     rm $PID_FILE 
  72.     echo -e "OPEN××× is already \033[41mstop\033[0m." 
  73.  
  74. while getopts sr SW;do 
  75.     case $SW in 
  76.         s) 
  77.             stop_open*** 
  78.             break 
  79.             ;; 
  80.         r) 
  81.             start_open*** 
  82.             break 
  83.             ;; 
  84.         ?) 
  85.             echo "open***_turn [s|r]" 
  86.     esac 
  87. done