需求:郵件服務器腳本ip做了切換,由原先的11.22.33.44,切換為11.22.33.55
需要把所有使用了11.22.33.44該ip的腳本改為11.22.33.55
示例:
#建2個測試文件
cat test1.txt
11.22.33.44
hello
11.22.33.44cat test2.txt
11.22.33.44
world#1.先找出哪些腳本包含該ip
grep 11.22.33.44 ./*
./test1.txt:11.22.33.44
./test1.txt:11.22.33.44
./test2.txt:11.22.33.44#2.查看切換后的效果
sed 's/11.22.33.44/11.22.33.55/' test1.txt test2.txt
11.22.33.55
hello
11.22.33.55
11.22.33.55
world#3.進行ip切換
sed -i 's/11.22.33.44/11.22.33.55/' test1.txt test2.txtcat test1.txt
11.22.33.55
hello
11.22.33.55cat test2.txt
11.22.33.55#備注:最好把ip,密碼之類的信息通過配置化的方式傳入,遇到這種情況直接改配置腳本是最直接的方式