Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
06-08-2012, 03:36 AM
|
#1
|
|
LQ Newbie
Registered: Jun 2012
Posts: 5
Rep: 
|
how to extract a 2-line pattern from a file using awk, grep, etc.
1. I want to identify usernames with the same password which is a security/audit issue.
2. The audit script output tests all such connections to the server database having the same password.
3. I need to extract only the usernames that connect successfully so that these passwords can be addressed. I know how to change passwords
4. Here is a sample of the huge output file:
SQL> connect AA/AA;
Connected.
SQL> connect B4B/B4B;
ORA-28000: the account is locked
Warning: You are no longer connected to ORACLE.
SQL> connect CCg/CCg;
ORA-01017: invalid username/password; logon denied
SQL> connect Dee/Dee;
Connected.
SQL> connect eR/eR;
ORA-28000: the account is locked
Warning: You are no longer connected to ORACLE.
SQL> connect Fdw2/Fwd2;
ORA-01017: invalid username/password; logon denied
Warning: You are no longer connected to ORACLE.
SQL> connect gAMw/gAMw;
Connected.
5. I would like an output file similar to this after pattern searching (i.e. only the connected usernames):
SQL> connect AA/AA;
Connected.
SQL> connect Dee/Dee;
Connected.
SQL> connect gAMw/gAMw;
Connected.
NB: the search should have nothing to do with usernames starting with an alphabet.
Much obliged,
Waiting in anticipation!
|
|
|
|
06-08-2012, 03:46 AM
|
#2
|
|
Senior Member
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 2,806
|
You can use: awk ' BEGIN { RS="SQL>" } ... ' and you will get the info in one line. You can use /Connected/ to find successful logins....
|
|
|
|
06-08-2012, 04:00 AM
|
#3
|
|
LQ Newbie
Registered: Jun 2012
Posts: 5
Original Poster
Rep: 
|
Thx Pan64.
Apologies I'm a beginner with awk.
Kindly explain to me how to just get the connected usernames from the output file.
By that I mean, after awk or whatever command or script, I get an output file as follows or similar:
SQL> connect AA/AA;
SQL> connect Dee/Dee;
SQL> connect gAMw/gAMw;
Tx
|
|
|
|
06-08-2012, 04:04 AM
|
#4
|
|
Senior Member
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 2,806
|
something like this:
Code:
awk ' BEGIN { RS="SQL>" }
/Connected/ { print "SQL> connect " $2 } ' inputfile
_____________________________________
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
Happy with solution ... mark as SOLVED
(located in the "thread tools")
|
|
|
|
06-08-2012, 04:19 AM
|
#5
|
|
LQ Newbie
Registered: Jun 2012
Posts: 5
Original Poster
Rep: 
|
tx for the expanded command.
I now get the following output:
SQL> connect connect
SQL> connect Connected.
SQL> connect connect
SQL> connect connect
SQL> connect connect
SQL> connect Connected.
SQL> connect connect
instead of the three connected usernames as in my first posting?
pls help!
|
|
|
|
06-08-2012, 05:01 AM
|
#6
|
|
LQ Newbie
Registered: Jun 2012
Posts: 5
Original Poster
Rep: 
|
i guess nobody knows the answer to my question!!
or did I not not explain it well enough??
hello Q&A forum????
|
|
|
|
06-08-2012, 06:00 AM
|
#7
|
|
Senior Member
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 2,806
|
it works fine for me, so probably you mistyped something or you have a different environment. Try to replace $2 with $1 or $3 and start again....
_____________________________________
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
Happy with solution ... mark as SOLVED
(located in the "thread tools")
|
|
|
1 members found this post helpful.
|
06-08-2012, 06:51 AM
|
#8
|
|
Member
Registered: Oct 2008
Location: Rousse, Bulgaria
Distribution: Slackware64
Posts: 80
Rep:
|
From grep's man page:
Code:
Context Line Control
-A NUM, --after-context=NUM
Print NUM lines of trailing context after matching lines. Places a line containing a group
separator (--) between contiguous groups of matches. With the -o or --only-matching option,
this has no effect and a warning is given.
-B NUM, --before-context=NUM
Print NUM lines of leading context before matching lines. Places a line containing a group
separator (--) between contiguous groups of matches. With the -o or --only-matching option,
this has no effect and a warning is given.
So just grep -B1 Connected <FILENAME> to get your results and please, restrain yourself from posts like http://www.linuxquestions.org/questi...9/#post4698608 some of us find it offensive. Especially when you didn't look at the documentation. Have a great day!
|
|
|
|
06-08-2012, 07:51 AM
|
#9
|
|
LQ Newbie
Registered: Jun 2012
Posts: 5
Original Poster
Rep: 
|
Thank u guys! $3 worked!
|
|
|
|
06-09-2012, 08:32 AM
|
#10
|
|
Moderator
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.4 OpenSuSE 12.2
Posts: 9,897
|
Quote:
Originally Posted by dcsmayei
i guess nobody knows the answer to my question!!
or did I not not explain it well enough??
hello Q&A forum????
|
May I ask what is the reason of such a rude comment? You posted this only 42 minutes after your last feedback. Maybe your issue was so urgent that you feel justified in addressing LQ members like that?!? Please, refrain from this behavior in the future and try to apply a bit of netiquette.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 08:19 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|