当前位置:网站首页>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 !
边栏推荐
- 原创翻译 | 机器学习模型服务工具对比:KServe,Seldon Core和BentoML
- The meta universe virtual digital human is closer to us | Sinovel interaction
- Model reasoning acceleration based on tensorrt
- database engine
- ABAP-CL_ OBJECT_ Collection tool class
- Explore gaussdb and listen to what customers and partners say
- SQL reported an unusual error, which confused the new interns
- Linux system Oracle 19C OEM monitoring management
- eval函数,全局、本地变量
- Runmaide medical opened the offering: without the participation of cornerstone investors, the amount of loss doubled
猜你喜欢
![[STL programming] [common competition] [Part 2]](/img/67/2a2d787680c0984f6c294a9ec3355b.png)
[STL programming] [common competition] [Part 2]

展现强劲产品综合实力 ,2022 款林肯飞行家Aviator西南首秀

Database log

A distribution fission activity is more than just a circle of friends

Sharing | intelligent environmental protection - ecological civilization informatization solution (PDF attached)

Installing services for NFS

On the drawing skills of my writing career

MongoDB简介及典型应用场景

元宇宙虚拟数字人离我们更近了|华锐互动

Csdn Skills Tree use Experience and Product Analysis (1)
随机推荐
When developing digital collections, how should cultural and Museum institutions grasp the scale of public welfare and Commerce? How to ensure the security of cultural relics data?
QT Chinese garbled code
Csdn Skills Tree use Experience and Product Analysis (1)
Database transactions
智联招聘的基于 Nebula Graph 的推荐实践分享
大促场景下,如何做好网关高可用防护
Database log
What is a stack?
云原生存储解决方案Rook-Ceph与Rainbond结合的实践
Postman Chinese tutorial (postman Chinese version)
Redis 大 key 问题处理总结
分享|智慧环保-生态文明信息化解决方案(附PDF)
原创翻译 | 机器学习模型服务工具对比:KServe,Seldon Core和BentoML
UOS prompts for password to unlock your login key ring solution
Installation and configuration of grayog new generation log collection early warning system
[数组]BM99 顺时针旋转矩阵-简单
Wechat IOS version 8.0.24 update release cache subdivision cleaning Online
【STL编程】【竞赛常用】【part 3】
UE4 essays: fstring, fname and ftext
Question brushing notes - tree (easy) - updating