脚本修改监控 I
#!/bin/bash
#xj
#create_time: 20200603
read -p "请输入需要修改的文件名:" file
echo -n "请输入原本的Redis端口:"
read rp
。 sed -i "s/$rp/6379/g" $file
echo -n "-----请输入原本的Memcache端口:"
read mp
sed -i "s/$mp/11211/g" $file
########这里sed 要用双引号,不然无法传参
## find xwfl_*|xargs -i sed -i 's/11216/11211/g' {} 单独执行么有问题
#注释lbs,img,等
if [ `grep -c lbs-restart $file` -gt "0" ];then
num=$(awk '/lbs-restart/ {print FNR}' $file)
批量修改同类文件中的某一段
#!/bin/bash
#单个文件执行OK,多个OK
#定义文件名称
s_file=$(ls *.cfg )
for file in $s_file
#输出行号
do
if [ `grep -c celery-restart $file` -gt "0" ];then
num=$(awk '/celery-restart/ {print FNR}' $file)
typeset -i a=$num-5
typeset -i b=$num+3
#删除
sed -i "${a},${b}d" $file
elif [ `grep -c qianfanwoker-restart $file` -gt "0" ];then
num=$(awk '/qianfanwoker-restart/ {print FNR}' $file)
typeset -i a=$num-5
typeset -i b=$num+3
#删除
sed -i "${a},${b}d" $file
fi
done
批量修改文件后缀名
for file in `find /usr/local/nginx/conf/vhosts -name "*.stop"`
do
mv $file ${file%.*}
done
find /usr/local/nginx/conf/vhosts/ -name "*.conf" |xargs -i mv {} {}.stop