arthur 发表于 2012-9-14 18:04:56

Unix Chell 检查指定进程是否存在

用cshell检查指定进程是否存在,如果不存在就启动该进程


#!/bin/csh
# Script Name: InvanTest check script for all trim devices
# Function : check InvanTest availability before program loading
# Rev0 - First release
# By:
###################################################################
# this scripts need to be released to /home3/msl/.ad6548_silveroff/
# and update trim_device_list to /home3/msl/.ad6548_silveroff/
###################################################################
set igft_chk_bypass=0 #maybe one day we need to bypass this check, just set to 1 to bypass
#### check whether bypass invantest check ####
if ( $igft_chk_bypass == 1) then
goto IGFT_SKIP_CHECK
endif

#### check trim dev list ####
set trim_dev_list="/home3/msl/.ad6548_silveroff/trim_dev_list.txt"
set igft_temp_file="/home/local_summary/igft_chk.temp"
set trimed_dev=0
if ( -f $trim_dev_list ) then
foreach record(`sed -n "/${DEVICE_ID}/p" $trim_dev_list`)
set trimed_dev=`expr $trimed_dev + 1`
end
if ( $trimed_dev == 0 ) then
echo "++++ this is not trim device ++++"
goto IGFT_SKIP_CHECK
endif
else
echo "++++ trimming devices list missing ++++"
goto IGFT_SKIP_CHECK
endif

#### start this invan test check ####
set igft_file="/floor/bin/xigft"
set wait_times=5
set igft_launch=0
set igft_locked=0
set init_wait_times=5

#### check process first to find any igft process running ####
echo ""
echo "checking igft process..."
IGFG_PROCESS_CHECK:
set igft_pro=0
foreach record(`ps -a|sed -n '/igft.td/p'`)
set igft_pro=`expr $igft_pro + 1`
end
set igft_pro=`expr $igft_pro / 4`
if ( $igft_pro > 0) then
echo "-->igft is running, you can start lot now"
#setenv and goto end
goto IGFT_CHECK_PASS_END
else
#### check whether locked ####
if ( $wait_times == 5 || $wait_times == 0 ) then
set igft_pro=0
foreach record(`ps -a|sed -n '/igft/p'`)
set igft_pro=`expr $igft_pro + 1`
end
set igft_pro=`expr $igft_pro / 4`
if ( $igft_pro > 0) then
set igft_locked=1
echo "-->igft is not running properly\!"
goto IGFT_CHECK_FAIL_END
endif
endif
#### no igft process found ####
if ( $igft_launch == 1 ) then
echo "-->still can not find igft process, $wait_times times to try..."
goto IGFT_START_SCRIPT
endif
echo "-->igft is not running\!"
endif


#### check igft start script file ####
echo ""
echo "checking igft software, please wait..."
IGFT_FILE_CHECK:
if ( -x $igft_file ) then
echo "-->igft software has been installed"
else
echo "-->igft software NOT installed"
#setenv and goto end
goto IGFT_CHECK_FAIL_END
endif


#### start igft and wait for a while to check process ####
echo ""
echo "start igft now, please wait until igft check pass\!"
$igft_file &
set igft_launch=1
sleep 4
IGFT_START_SCRIPT:
while ( $wait_times > 0 )
set wait_times=`expr $wait_times - 1 `
sleep 4
#check process again, got to end if found
goto IGFG_PROCESS_CHECK
end
echo "-->igft start failed\!\!"
goto IGFT_CHECK_FAIL_END


#### pass end of igft check script ####
IGFT_CHECK_PASS_END:
echo "IGFT_CHECK_STATUS~PASS" > $igft_temp_file
chmod 777 $igft_temp_file
echo "+-----------------------------------------------------+"
echo "| invantest check pass, you can continue starting lot |"
echo "+-----------------------------------------------------+"
exit 0


#### fail end of igft check script ####
IGFT_CHECK_FAIL_END:
echo "IGFT_CHECK_STATUS~FAIL" > $igft_temp_file
chmod 777 $igft_temp_file
echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
echo "x invantest check failed, can not start\! x"
echo "x please inform LSG to check invantest\! x"
echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
setenv LD_LIBRARY_PATH /image/bin.rls/custom/qa_custom/scripts/scan_startlot_endlot/STATS/ESUMMARY/lib
if ( $igft_locked == 1) then
echo "x IG.FT most probably locked\! x"
echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
/home3/msl/.ad6548_silveroff/Locked_InvanTest_Error &
else
/home3/msl/.ad6548_silveroff/No_InvanTest_Error &
endif
setenv LD_LIBRARY_PATH /image/bin.rls/lib
echo "deleting program ... "
delete
echo "program deleted"
exit 1


#### skip IGFT check, maybe this script need to by pass one day ####
IGFT_SKIP_CHECK:
echo "IGFT_CHECK_STATUS~BYPASS" > $igft_temp_file
chmod 777 $igft_temp_file
echo "+--------------------------+"
echo "| invantest check bypassed |"
echo "+--------------------------+"
exit 0

页: [1]
查看完整版本: Unix Chell 检查指定进程是否存在