linux写脚本模拟并发,linux并发执行shell脚本模版以及案例

模版

#!/bin/bash

#扫描环境文件,根据需要设置

source /root/gsql_env_v2.sh

echo "################################################################"

temp_fifo_file=/tmp/$$.fifo

mkfifo $temp_fifo_file

exec 6<>$temp_fifo_file

rm $temp_fifo_file

#设置并发进程数

temp_thread=20

for ((i=0;i

do

#设置并发占位

echo

done >&6

while read line

do

read -u6

{

echo $line

#gsql -h 25.34.0.130 -p 8000 -U sjzt_admin -d tjdl_sjzt_db1 -W ^B1myD*c3! -c "select * from public.table_map_system_sc;

#\q"

#添加自己执行的业务逻辑即可

echo >&6

}&

done

# 等待所有的执行完

wait

exec 6>&-

案例

CREATE TABLE public.standard_gsql_status (

standard_table character varying(500),

standard_date timestamp(0) without time zone,

standard_status character varying(100),

begin_time timestamp(0) without time zone,

end_time timestamp(0) without time zone

)

#!/bin/bash

source /root/gsql_env_v2.sh

echo "################################################################"

log_date=`date +%Y-%m-%d`

temp_fifo_file=/tmp/$$.fifo

mkfifo $temp_fifo_file

exec 6<>$temp_fifo_file

rm $temp_fifo_file

#设置进程数

temp_thread=20

for ((i=0;i

do

echo

done >&6

while read line

do

read -u6

{

table_name=`echo $line|awk -F ',' '{print $4}'`

gsql -h 25.34.0.130 -p 8000 -U sjzt_admin -d tjdl_sjzt_db1 -W ^B1myD*c3! -c "

delete from public.standard_gsql_status where standard_date = '$log_date' and standard_table = $table_name;

insert into public.standard_gsql_status(standard_table,standard_date,standard_status,begin_time) values ($table_name,'$log_date','running',sysdate); \q"

#-v "ON_ERROR_STOP=1"

gsql -h 25.34.0.130 -p 8000 -U sjzt_admin -d tjdl_sjzt_db1 -W ^B1myD*c3! -v "ON_ERROR_STOP=1" -c "

declare

var_cnt text;

begin

select $line into var_cnt;

end "

if [ $? = 0 ];then

gsql -h 25.34.0.130 -p 8000 -U sjzt_admin -d tjdl_sjzt_db1 -W ^B1myD*c3! -c "

update public.standard_gsql_status set standard_status = 'success',end_time=sysdate where standard_date = '$log_date' and standard_table = $table_name; \q"

else

gsql -h 25.34.0.130 -p 8000 -U sjzt_admin -d tjdl_sjzt_db1 -W ^B1myD*c3! -c "

update public.standard_gsql_status set standard_status = 'fail',end_time=sysdate where standard_date = '$log_date' and standard_table = $table_name; \q"

fi

echo >&6

}&

done

# 等待所有的执行完

wait

exec 6>&-

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值