当前位置:网站首页>Shell command used in actual work - sed
Shell command used in actual work - sed
2022-06-27 20:57:00 【I am fat tiger】
background
At present, the interface automation of running is through Testng + Jenkins To do the , But the project may run on different platforms , Different platforms have different ip.
At present, it is used Jenkins Parameterized build function of , Every time I run , Manually enter a ip, And then ip Automated testing of services .
Testng The configuration file for the framework is application.properties, We will serve ip Record in this file .
demand
According to from Jenkins Incoming parameter , Dynamic modification application.properties Medium ip Variable , Then carry out the follow-up test .
application.properties Example
server_ip=http://192.168.100.100
port=9000
path=/home/data
Demand analysis
At present, the methods thought of are 2 individual :
- use python The script reads the file , Regular substitution formulates text , Generate a new file
- use shell Script to operate
From the simplest point of view , Give priority to shell Methods .
Linux Yes 3 Swordsman : grep ,sed, awk. among grep Mainly for filtration , sed Mainly do text related processing ( Such as modification and replacement ),awk Mainly do data processing , Report output, etc . So we should consider using sed Order to solve this problem .
Actual operation
- From the Internet search under the relevant sed usage , Reference link : https://blog.csdn.net/ganfanren00001/article/details/122765854
What is used this time sed Command screenshot
- The lines , This is how I use
sed "/server_ip=/c server_ip=http://192.168.200.200" application.properties
- But there's a problem with that , This modification is only temporary , It doesn't actually affect the real file . Actually sed There is one -i Parameters , Add this parameter to the real file , So under optimization
sed -i "/server_ip=/c server_ip=http://192.168.200.200" application.properties
- This command runs through the local area , The next step is to integrate into Jenkins Use this command in
- First, in the Jenkins in , Select parametric build , The parameter name I define is server_ip
- stay shell Use this variable in the script
notes : Jenkins The format of using the passed in variable is :${ Variable name }
#!/bin/bash
echo " Incoming ip yes :${server_ip}"
# Modify the project according to the passed in parameters ip
cd /home/data/jenkins/workspace/maven_testng/maven_testng/src/main/resources
sed -i "/server_ip=/c server_ip=http://${server_ip}" application.properties
echo " The item has been changed to an incoming ip: ${server_ip}"
Step on the pit : sed Use double quotation marks after the command , You can't use single quotes , Otherwise, the variable will be recognized as a normal string !
边栏推荐
- CSDN 技能树使用体验与产品分析(1)
- CocosCreator播放音频并同步进度
- [array]bm99 clockwise rotation matrix - simple
- MySQL速成——第一天--基础入门
- 花了6个月时间完成本科优秀毕业设计,我做了什么?
- 云原生存储解决方案Rook-Ceph与Rainbond结合的实践
- Database transactions
- After kotlin wechat payment callback, the interface is stuck and uipagefragmentactivity windowleft is thrown
- "Good voice" has been singing for 10 years. How can the Chinese language in the starry sky sing well in HKEx?
- Model reasoning acceleration based on tensorrt
猜你喜欢

海量数据出席兰州openGauss Meetup(生态全国行)活动,以企业级数据库赋能用户应用升级

优维HyperInsight:掘金164.94亿美元可观测市场的“金锄头”?

SQL审核平台权限模块介绍和账号创建教程

Postman Chinese tutorial (postman Chinese version)

database engine

Openharmony hisysevent dotting and calling practice of # Summer Challenge (L2)

muduo

低代码开发平台是什么?为什么现在那么火?

"Good voice" has been singing for 10 years. How can the Chinese language in the starry sky sing well in HKEx?

谈谈我写作生涯的画图技巧
随机推荐
[数组]BM99 顺时针旋转矩阵-简单
Installation and configuration of grayog new generation log collection early warning system
Binary tree related problems 2
Backtracking related issues
Pycharm common functions - breakpoint debugging
大促场景下,如何做好网关高可用防护
Necessary software tools in embedded software development
Cloud native Security Guide: learn kubernetes attack and defense from scratch
Abap-sm30 check before deletion
Recommended practice sharing of Zhilian recruitment based on Nebula graph
最佳实践:优化Postgres查询性能(下)
Database index
如何降低用户关注的非必要页面的权重传递?
爱数课实验 | 第七期-基于随机森林的金融危机分析
Graduation design of police report convenience service platform based on wechat applet
Yyds dry goods counting SQL sub query
Cerebral Cortex:从任务态和静息态脑功能连接预测儿童数学技能
Model reasoning acceleration based on tensorrt
动物养殖生产虚拟仿真教学系统|华锐互动
At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions