- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Help in a script
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-10-2008 08:49 AM
09-10-2008 08:49 AM
sort passwd1 passwd2 passwd3 | awk -F: '
BEGIN { getline; name = $1; uid = $3 }
{
if ($1 == name) {
uid = uid " " $3 # concat
} else {
print name, uid # print last
name = $1; uid = $3
}
}
END { print name, uid } '
It gives output like the following:
ufeabjp 16128 16128 16128
ufeabln 16096 16096 16096
ufeabms 16118 16118 16118
This script prints username followed by his ids in three servers. I want to add some more information to it like Real name, description and if possible I want to add the time and date when the user logged in last time.
The desired output is:
username userid userid userid Name Desc lastlogin
Can any one help me in modifying the script?
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2008 09:13 AM
09-10-2008 09:13 AM
Re: Help in a script
If you are more specific about your requirements, someone might be able to help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2008 09:14 AM
09-10-2008 09:14 AM
Re: Help in a script
> I want to add the time and date when the user logged in last time.
From which server would you want the last login information, or don't you really want the most *recent* timestamp of all of them?
We offered considerable insight if you revisit your thread here:
http://forums12.itrc.hp.com/service/forums/questionanswer.do?threadId=1263622
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2008 09:31 AM
09-10-2008 09:31 AM
Re: Help in a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2008 09:34 AM
09-10-2008 09:34 AM
Re: Help in a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2008 09:34 AM
09-10-2008 09:34 AM
Re: Help in a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2008 08:15 AM
09-11-2008 08:15 AM
SolutionAs JRF mentioned, look at your other thread.
If you want the name and description, you would need to capture more fields:
BEGIN { getline; name = $1; uid = $3; rname = $5 }
...
print name, uid, rname # print last
name = $1; uid = $3; rname = $5
...
END { print name, uid, rname } '
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2008 09:37 AM
09-11-2008 09:37 AM
Re: Help in a script
Thanks alot for your help, could you please help me a little bit more. Can you please little more explain working of your script so that I can modify it further?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2008 09:58 AM
09-11-2008 09:58 AM
Re: Help in a script
From the one in:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1263622
sort passwd1 passwd2 passwd3 | awk -F: '
function do_print() { # centralzed
save_line = name " " uid " " rname # add uid and real name
# get the info from last
last_command = "last -1 " name
name = $1; uid = $3; rname = $5
FS=" "
xx = last_command | getline
if (xx == 1)
print save_line, $3, $4, $5, $6
else
print save_line, "???"
FS=":" # restore
}
BEGIN { getline; name = $1; uid = $3; rname = $5 } # read first line
{
if ($1 == name) { # combine same UIDs
uid = uid " " $3
} else {
do_print() # if a break, print previous
}
}
END { do_print() } '
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2008 10:05 AM
09-11-2008 10:05 AM
Re: Help in a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2008 10:41 AM
09-11-2008 10:41 AM
Re: Help in a script
> is that c shell scripting ?
No, Dennis used 'awk'. This is invoked with the command 'awk'. The actual script is encapsulated between the single quote marks. A rather nice tutorial can be found here, although the tutorial is the enhanced GNU 'awk' which adds features not present in HP's more standard version.
http://www.gnu.org/software/gawk/manual/
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2008 11:09 AM
09-11-2008 11:09 AM
Re: Help in a script
I wouldn't be caught dead using the scummy C shell. ;-)
You can also put the awk script in a file and invoke with: awk -f foo.awk