欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

shell基础入门学习

程序员文章站 2022-04-15 12:48:58
1 shell的集合 declare -A ihmap=() FILE_ALL=/opt/config/iphost for d in `cat $FILE_ALL`;do eval $...

1 shell的集合

declare -A ihmap=()
FILE_ALL=/opt/config/iphost
for d in `cat $FILE_ALL`;do eval $(echo $d|awk -F',' '{printf("a=%s b=%s",$2,$1)}');ihmap[$a]=$b;done

countha=0
IFS=';'
for hips in ${hadoopIp[@]}; do
let countha+=1
IFS=','
for hip in ${hips[@]};do
if [ $countha == 1 ];then
echo ${ihmap[$hip]},$hip,root,root,NN>>/opt/config/iphostuserpwdtype
elif [ $countha == 2 ];then
echo ${ihmap[$hip]},$hip,root,root,DN>>/opt/config/iphostuserpwdtype
fi
done
done

2 文件的锁定及进程的存在判断

脚本1 start.sh:

flock -xn /var/run/aa.lock -c 'sh /opt/scripts/start_all.sh $1'

脚本2 start_all.sh:

真正执行任务的脚本,略

进程判断

可尝试:

infos=$(ps -ef|grep '' |grep -v grep);