#需求
原内容10.221.29.30 修改后: qq1-5f ansible_ssh_host=10.221.29.30
原内容10.225.32.75 修改后: qq6-10f ansible_ssh_host=10.225.32.75
原内容10.221.249.127 修改后: qq11-15f ansible_ssh_host=10.221.249.127
#文件展示
[root@Master opt]# tree /opt/ /opt/ ├── 1.txt ├── 2.txt ├── gai.sh └── hosts 0 directories, 4 files
#hosts文件
cat /opt/hosts 10.221.29.30 10.225.32.75 10.221.249.127 10.221.29.1 10.225.37.100 10.225.32.63 10.221.252.191 10.225.32.205 10.221.101.13 10.143.94.59 10.232.48.163 10.232.44.180 10.207.161.216 10.143.82.89 10.225.32.81
#脚本内容
[root@Master opt]# cat gai.sh #!/bin/bash for i in `cat /opt/hosts` do echo "ansible_ssh_host=$i" >> /opt/1.txt done i=0 for b in {1..85} do er=`expr $b % 5` if [ $er -eq 0 ];then yi=`expr $b - 4` let i++ c=`head -"$i" /opt/1.txt | tail -1` echo "qq"$yi"-"$b"f $c" >> 2.txt fi done
#脚本执行,1.txt内容查看
[root@Master opt]# sh a.sh [root@Master opt]# cat 1.txt ansible_ssh_host=10.251.132.52 ansible_ssh_host=10.251.124.52 ansible_ssh_host=10.221.29.30 ansible_ssh_host=10.225.32.75 ansible_ssh_host=10.221.249.127 ansible_ssh_host=10.221.29.1 ansible_ssh_host=10.225.37.100 ansible_ssh_host=10.225.32.63 ansible_ssh_host=10.221.252.191 ansible_ssh_host=10.225.32.205 ansible_ssh_host=10.221.101.13 ansible_ssh_host=10.143.94.59 ansible_ssh_host=10.232.48.163 ansible_ssh_host=10.232.44.180 ansible_ssh_host=10.207.161.216 ansible_ssh_host=10.143.82.89 ansible_ssh_host=10.225.32.81
#修改后的配置文件
[root@Master opt]# cat 2.txt qq1-5f ansible_ssh_host=10.251.132.52 qq6-10f ansible_ssh_host=10.251.124.52 qq11-15f ansible_ssh_host=10.221.29.30 qq16-20f ansible_ssh_host=10.225.32.75 qq21-25f ansible_ssh_host=10.221.249.127 qq26-30f ansible_ssh_host=10.221.29.1 qq31-35f ansible_ssh_host=10.225.37.100 qq36-40f ansible_ssh_host=10.225.32.63 qq41-45f ansible_ssh_host=10.221.252.191 qq46-50f ansible_ssh_host=10.225.32.205 qq51-55f ansible_ssh_host=10.221.101.13 qq56-60f ansible_ssh_host=10.143.94.59 qq61-65f ansible_ssh_host=10.232.48.163 qq66-70f ansible_ssh_host=10.232.44.180 qq71-75f ansible_ssh_host=10.207.161.216 qq76-80f ansible_ssh_host=10.143.82.89 qq81-85f ansible_ssh_host=10.225.32.81
本文出自 “wsyht的博客” 博客,请务必保留此出处http://wsyht2015.blog.51cto.com/9014030/1792383
转载于:https://blog.51cto.com/chenx1242/1792455