您的位置:首页 > 运维架构 > Shell

Shell之定时拉起脚本

2015-11-30 18:02 609 查看
## 定时拉起脚本scan_shell.sh

#!/bin/sh
########################################################################################
# Define app execute command here.(please type full name of programs and args)
########################################################################################
appcmds[0]='/usr/test/app/cmdwifi'
appcmds[1]='/usr/test<span style="font-family: Arial, Helvetica, sans-serif;">/app/server_cma_module'</span>
appcmds[2]='/usr/test/app/logmodule_server'
appcmds[3]='/usr/test/app/bitemodule_server'
appcmds[4]='/usr/test/app/proxydb'
appcmds[5]='/usr/test/app/server_suu'
appcmds[6]='/usr/test/app/seat_control'
appcmds[7]='/usr/test/app/relay_module'
appcmds[8]='/usr/sbin/named -u named'
appcmds[9]='/usr/sbin/dhcpd eth1'
appcmds[10]='/opt/lampp/sbin/mysqld'
appcmds[11]='/opt/lampp/bin/httpd'
appcmds[12]='/usr/donica/app/ku_cma'

LOG_FILE='/usr/donica/script/scanproc.log'
#sleep 60

cd /usr/donica/script/
mv scanproc.log scanproc.log.last

########################################################################################
# Caution: please DO NOT modify the scripts below.
########################################################################################
#check app command if exist.
for cmd in "${appcmds[@]}"; do
filename=$(echo $cmd|awk '{print $1}')
echo ">> Checking sh file: app command - " $cmd
if [ -f "$filename" ]; then
echo ">> SUCCESS~~~~"
else
echo ">> FAILED!!!! please make sure app command exist."
exit
fi
done

checkprocess()
{
script_name=$(basename $0)
if [ "$1" = "" ];
then
return 1
fi
process_num=$(ps -ef |grep "$1" |grep -v "grep" | grep -v $script_name | wc -l)
return $process_num
}

#######################################################################################
#Some process need to read config file,we must use correct path
######################################################################################
cd /usr/donica/app/

echo ">> Checking process status..."
nums=${#appcmds[*]}

while [ 1 ] ; do

for((i=0; i<nums; i++)); do

appcmd=${appcmds[i]}

# get app name from app cmd
appname=${appcmd%% *}
appname=${appname##*/}

$(checkprocess $appname)
check_result=$?
if [ $check_result -eq 0 ]; then
set `date`
printf ">> ["$appname"] DOWN. Trying to start it!"
echo "["$2" "$3" "$4" "$6"] ["$appname"] DOWN. Trying to start it!" >> $LOG_FILE

#######################################################################################
#Because of some system services, we should use different start command to start them
#######################################################################################
if [ $i -eq 8 ];then
printf "\n"
service named start
elif [ $i -eq 9 ];then
printf "\n"
service dhcpd start
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: