shell多进程脚本

时间:2021-11-11 02:45:24
#!/bin/bash

python_path=/home/huaw/crawler
python_name=list_all_v6_crawler.py
MAX_SYNC_PROCESS=40
echo "max allowed ic_stat_company_submit process is $MAX_SYNC_PROCESS"
current_sync_num=`ps -ef|grep $python_name | wc -l |grep -v grep`
current_sync_num=$[current_sync_num-1]
echo "current started ic_stat_company_submit process count $current_sync_num"
if [ $current_sync_num -lt $MAX_SYNC_PROCESS ]
then
sync_num=$[ MAX_SYNC_PROCESS-current_sync_num]
echo "not reach max processes,will start $sync_num process..."
for((i=1;i<=$sync_num;i++));do
echo "process will be started..."
cd $python_path
python $python_name >> list.log 2>&1 & 
done
else
echo "runing....."
fi