shell腳本--02修改配置文件中的IP
阿新 • • 發佈:2018-08-03
ali for -- gre ast 執行 修改配置 type ssh
1.修改Json中的IP
$ ./ip.sh ‘8.8.8.1‘
#!/bin/bash
#localIP=$(command)
#
localIP=‘/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|grep 8|awk ‘{print $2}‘|tr -d "addr:"‘
for ip in $(< /home/.../conf/env.json);do if [ ${ip} == "9.9.0.224" ] then sed -i ‘s/${ip}/${localIP}/g‘ /../env.json elif[ ${ip} == "9.9.0.18" ] then sed -i ‘s/${ip}/$1/g‘ /../env.json fi done
2.修改Envtype與Envuser
$ ./env.sh test
1.Ansible調用各個Agent腳本執行,判斷envtype="solution"時更新為$1
2.ssh root@${ip}
"sed -i ‘s/1/3/g‘ /home/../json"
3.嵌套循環
for file in /home/../*.json do echo "$file:" for ... done done
4.判斷是哪個環境
for file in /home/.../* if [ -d "$file" && "$file"=="taskserver" ] then echo "$file means localhost is server" elif [ -d "$file" && "$file" == "taskmaster"] then echo "" elif [ -d "$file" && "$file" == "env_agent"] then echo "" fi done
shell腳本--02修改配置文件中的IP