- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk helppp
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2005 11:54 PM
09-19-2005 11:54 PM
If I want to do like this:
#who -T|awk '$6!=192.120.20.107 and $1=root {print $9}'
Why this script does not work.Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2005 11:57 PM
09-19-2005 11:57 PM
Re: awk helppp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 12:05 AM
09-20-2005 12:05 AM
Re: awk helppp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 12:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 12:10 AM
09-20-2005 12:10 AM
Re: awk helppp
If you mean to print the last field, then 'awk' counts fields one-relative. The logical 'and' operator is also '&&'. Did you mean:
# who -T|awk '$8!~/192.120.20.107/ && $1~/root/ {print $9}'
...or for the last field of the line:
# who -T|awk '$8!~/192.120.20.107/ && $1~/root/ {print $NF}'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 12:12 AM
09-20-2005 12:12 AM
Re: awk helppp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 12:25 AM
09-20-2005 12:25 AM
Re: awk helppp
This works for me:
who -T | awk '/^root/&& !/192.120.20.107 / {print $NF}'
it looks for a line starting with 'root' and not containing a specific IP address anywhere in the line.
please note that the 'dots' in the ip address are in fact regular expression elements for 'any' char. So if the line contained 192X120Y20Z107 then it woudl also be disgarded, but this seems reasonable considering the intended use.
hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 12:26 AM
09-20-2005 12:26 AM
Re: awk helppp
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 12:33 AM
09-20-2005 12:33 AM
Re: awk helppp
--> "Why the above script print all user root even if this user have ip 192.120.20.107??".
The answer is that you negated (with "!") the IPaddress, so you asked for all logins that do NOT match that address but (and) are 'root' users.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 12:38 AM
09-20-2005 12:38 AM
Re: awk helppp
All solutions stated above are negating 192.120.20.107 IP-Address and checking with root user also. Check with example and let us know If you find same problem again.
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 12:41 AM
09-20-2005 12:41 AM
Re: awk helppp
who -T | perl -ne '$ip=(split)[8] if !/root.*192.120.20.107/;print $ip . "\n";
hth.'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 12:51 AM
09-20-2005 12:51 AM
Re: awk helppp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 12:57 AM
09-20-2005 12:57 AM
Re: awk helppp
--> I wan to print user root except root with ip 192.120.20.107
Then one way is:
# who -T|awk '$1~/^root/ && $NF!~/192.120.20.107/ {print $0}'
...use print $0 to see the whole line or if you only want the last field, use print $NF.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 01:05 AM
09-20-2005 01:05 AM
Re: awk helppp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 01:17 AM
09-20-2005 01:17 AM
Re: awk helppp
--> If I want to print all user root except root for ip 192.120.20.107 and 192.120.20.108.How to change this script?
# who -T|awk '$1=="root" && $NF!="192.120.20.107" && $NF!="192.120.20.108" {print $0}'
...is one way. I have changed from using regular expressions to string comparisons for exact matching of the fields. Thus, if you had "root" and "rootuser" this would only match "root" in field #1. This was one point that Hein had made.
You could also do:
# who -T|awk '$1=="root" && $NF~/192\.120\.20\.10[78]/ {print $0}'
This last one uses a match of the last field with a regular expression that matches EITHER of the IP address YOU WANT while avoiding the ambiguity of the dot character too.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 03:35 PM
09-20-2005 03:35 PM