- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- About awk,shell program!
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
Discussions
Discussions
Discussions
Forums
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
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
тАО07-26-2004 02:18 PM
тАО07-26-2004 02:18 PM
I need a shell.It can use awk.I need this function,that using '/etc/passwd','/etc/group' and '/etc/last -1' to get a file.The file like:
UserUser GroupGroup $HOME
ID Name ID Name LastLoginDirectory
0 root 3 sys at Nov 15/
Who can help me?thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-26-2004 04:54 PM
тАО07-26-2004 04:54 PM
Re: About awk,shell program!
$file = "/etc/group";
open (FILE,"< $file") || die "Could not open $file";
while (
($name,$x,$id) = split (/:/);
$group{$id} = $name;
}
close (FILE);
$file = "/etc/passwd";
open (FILE,"< $file") || die "Could not open $file";
while (
($name,$pass,$id,$gid,$x,$pwd) = split (/:/);
$_ = `last -1 $name`;
@last = split;
$at = ($_) ? "at $last[3] $last[4]" : "
print "$id $name $gid $group{$gid} $at $pwd\n";
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-26-2004 05:01 PM
тАО07-26-2004 05:01 PM
Re: About awk,shell program!
Thank you,can you use awk to program?I need it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-26-2004 05:39 PM
тАО07-26-2004 05:39 PM
Solutionawk -f x.awk /etc/passwd
where x.awk contains:
BEGIN { FS = ":";
while(getline < "/etc/group") {
group[$3]=$1;
}
}
{ name = $1;
id = $3;
gid = $4;
pwd = $6;
FS = " ";
$0 = "hey, there was no time";
"last -1 " name | getline;
month = $4;
day = $5;
FS = ":";
print id,name,gid,group[gid],"at",month,day,pwd;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-26-2004 05:54 PM
тАО07-26-2004 05:54 PM
Re: About awk,shell program!
$ awk -f x.awk /etc/passwd
awk: Cannot find or open file x.awk.
The source line number is 1.
The error context is
>>> <<<
$
$
$ where x.awk contains:
sh: where: not found.
$
$ BEGIN { FS = ":";
sh: BEGIN: not found.
$ while(getline < "/etc/group") {
sh: Syntax error: `{' is not expected.
$ group[$3]=$1;
sh: 3: Parameter not set.
$ }
sh: Syntax error: `}' is not expected.
$ }
sh: Syntax error: `}' is not expected.
$ { name = $1;
> id = $3;
> gid = $4;
> pwd = $6;
> FS = " ";
> $0 = "hey, there was no time";
> "last -1 " name | getline;
> month = $4;
> day = $5;
> FS = ":";
> print id,name,gid,group[gid],"at",month,day,pwd;
> }
sh: 1: Parameter not set.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-26-2004 06:13 PM
тАО07-26-2004 06:13 PM
Re: About awk,shell program!
You were not supposed to cut & paste the whole thing!
I showed a sample command line with x.awk.
This x.awk was supposed to be a file (which you can call anythign else!) that you created with the text from the rest of the reply.
So x.awk should start with: "BEGIN { FS ..."
and the last lines would be:
print id,name,gid,group[gid],"at",month,day,pwd;
}
You can also put it all in a singel file by playing with <
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-26-2004 06:16 PM
тАО07-26-2004 06:16 PM
Re: About awk,shell program!
I think you have typed everything continuosly....
create a file x.awk
with the content given in the reply above..
Then in shell prompt give
awk -f x.awk /etc/passwd
Regards,
Ram.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-26-2004 06:42 PM
тАО07-26-2004 06:42 PM
Re: About awk,shell program!
Sorry,because of busy,so I can't read your program carefully.
Then,I make a file named temp_test.awk,run it,successful.That is my wanted!
Thank you very muck!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-27-2004 02:20 AM
тАО07-27-2004 02:20 AM
Re: About awk,shell program!
But I am a little dissapointed that you initially did not even bother in the slightest to understand the solution.
The when it blows up, that should give you a hint to check it out a little no?
Myself, I answer questions here NOT primarely to try to solve your problems, but to teach you how you could solve your problem, and others similar to it in the future.
I'm pretty sure most folks helping here feel similar.
"Give a man a fish, and you feed him
for one day. Teach a man to fish, and you feed him for a lifetime"
Kindest regards,
Hein.