LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-09-2015, 10:58 AM   #1
worm5252
Member
 
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX, OS X
Posts: 567

Rep: Reputation: 57
Post sed regex to blank our password entries


I have some logfiles that print out passwords in clear text. I need to a quick sed command to blank out the passwords so I can simply copy and paste log entries in an email for communication. Here is an example so one of those entries

Quote:
[2015-09-09 11:19:17,298] [DEBUG] [qtp1603837828-10 - /] com.zenoss.zenpacks.zenjmx.ZenJmxService$JMXCollector:73 - processing [connectionKey=service:jmx:iiop://server1.mydomain.com:12345/jndi/weblogic.management.mbeanservers.runtime, operationParamValues=, dptypes=[Ljava.lang.Object;@56609959, password=somecleartextpassword, authenticate=true, username=somejavauser, component=SOA_WorkManager_CompletedRequest, datasourceId=SOA_WorkManager_CompletedRequest, sourcetype=JMX, operationParamTypes=, jmxRawService=service:jmx:iiop://server1.mydomain.com:12345/jndi/weblogic.management.mbeanservers.runtime, commandTemplate=, cycletime=300, enabled=true, dps=[Ljava.lang.Object;@5ff3ce5c, attributePath=, jmxProtocol=RMI, operationName=, rrdPath=Devices/server1.mydomain.com, objectName=com.bea:ServerRuntime=soa_ms1,Name=wm/SOAWorkManager,Type=WorkManagerRuntime,ApplicationRuntime=soa-infra, rmiContext=jmxrmi, severity=3, eventClass=/Status/JMX, attributeName=CompletedRequest, jmxPort=12345, eventKey=, manageIp=1.1.1.1, device=server1.mydomain.com]
I need to be able to search for password= and then replace whatever is there with *****. The value after password= will be different every time as this will be used for device specific logs.

For testing I took the above entry and put it in a test.txt file. I have tried this one but It cuts out too much data from the log.
Code:
sed -e 's/password=.*\,/password=\*\*\*\*\*\,/g' test.txt
Which Produces the following output
Quote:
[2015-09-09 11:19:17,298] [DEBUG] [qtp1603837828-10 - /] com.zenoss.zenpacks.zenjmx.ZenJmxService$JMXCollector:73 - processing [connectionKey=service:jmx:iiop://server1.mydomain.com:12345/jndi/weblogic.management.mbeanservers.runtime, operationParamValues=, dptypes=[Ljava.lang.Object;@56609959, password=*****, device=server1.mydomain.com]
Obviously my sed regex is not right since I am replacing too much text in the string. Any help in tightening up this regex to replace just the password is appreciated.

Last edited by worm5252; 09-09-2015 at 10:59 AM.
 
Old 09-09-2015, 11:53 AM   #2
worm5252
Member
 
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX, OS X
Posts: 567

Original Poster
Rep: Reputation: 57
I figured this out finally, on my own. the password=.*\, is what was messing me up, and I knew that, just wasn't sure what it should be. The code that works is

Quote:
sed -e 's/password=[^ ]*\,/password=\*\*\*\*\*\,/g' test.txt
 
  


Reply

Tags
log, password, regex, sed



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex or Sed grob115 Programming 6 10-02-2012 09:00 PM
sed and regex help zski128 Programming 5 12-13-2011 10:30 AM
sed regex say_hi_ravi Programming 3 09-15-2011 02:12 AM
[SOLVED] sed regex schneidz Programming 1 02-28-2011 06:46 PM
regex with sed to process file, need help on regex dwynter Linux - Newbie 5 08-31-2007 05:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration