shell基础

来源:互联网 发布:三维人像综合数据门 编辑:程序博客网 时间:2024/05/18 01:30

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);


3 shell 只处理文件倒数第二行

# cat tt
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
# sed '$!N;$s/,//' tt
1,
2,
3,
4,
5,
6,
7,
8,
9
10,


只处理倒数第三行:

 sed -n ':a;${s/;/,/;p;q};N;4,${P;D};ba' tt


sed博大精深,慢慢积累咯~

原创粉丝点击