Search the web
Sign In
New User? Sign Up
geeksthatgawk · for GNU Awk questions & discussions
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Help needed   Message List  
Reply | Forward Message #44 of 221 |
Hi There,
I'm having some trouble with my unix work and was
wondering if you could lend me a hand. The main
problem has to do with an application called awk.

I've to create reports based on users and groups.
I'm still new to this though i know a bit on unix.
The OS i'm using to carry out this programming
is Red Hat Linux 7.2 using Bourne shell.

I've included coding that i've done on my end but
how do i get it to show all the groups(everything)
and users(all).

My Question
------------------
Create a couple of Unix Shells scripts that do the following:

Screen 1:

UNIX UTILITY

1. Show Groups (ALL
2. Show Users (All)
3. Show Groups (Enter)
4. Show Users
5. Hello (About the Software)
6. Exit

Enter Choice:

Any choice other than 0 to 5 should generate an error message.

On Selecting 1:

Show a report in the following format:

Group ID Group Name
---------- -------------
---------- -------------

The report should be shown page by page if it extends more than one
page.
After the last page there must be a message "Press any key to
continue..."
then the menu should come back.

On Selecting 2:

The report shown should be

Group ID -----------
Group Name ---------
Total Users ----------

User ID User Name Home Directory
------------- ----------------- ------------------------

Report should be page by page(should be displayed on screen)
Last page should display "Press any key to continue..."
Show the main menu upon return


My Code
-------------
#!/bin/sh
# Program name: menu
# Written by: Vinod Shankar Menon
# Date: 28th April 2002
# Description: This program prints a menu and executes choice.
Then it reprints the menu for another selection.

quit=n
clear
while test "$quit" = "n"
do
echo "-----------------"
echo "SANKHYA INSTITUTE"
echo "-----------------"
echo
echo "1. Show Groups(All)"
echo "2. Show Users(All)"
echo "3. Show Groups(Enter)"
echo "4. Show Users(Enter)"
echo "5. About the Software"
echo "6. Exit"
echo

# prompt for user input
echo -n "Enter Choice: .\b"

# set variable named choice to value of user input
read choice

# start case based on variable selection
case $choice in
1) awk -f script.awk /etc/passwd;;

2) awk -F: '$1 == "'$USER'" {print "Group ID:"$4}' /etc/passwd
awk -F: '$1 == "'$USER'" {print "Group Name:"$1}' /etc/passwd
echo Total Users:
echo
echo "User ID User Name Home Directory"
awk -F: '$1 == "'$USER'" {print $3 "\t" $1 "\t\t"
$6}' /etc/passwd;;

3) echo "Showing Groups...";;

4) echo "Getting Users Info....";;

5) echo "About the Software...";;

6) quit=y;;
*) echo "Invalid Choice! Try Again!"
sleep 5
esac
done

The script.awk code
--------------------------
#!/bin/sh
BEGIN {
FS=":" #remember that the passwd file uses colons
OFS=" " #we_re-setting the output to a TAB
print "Group ID", "Group Name"
}
/stud/ {print $4, "\t" $1}




Thu Sep 19, 2002 11:24 am

hacker80n
Offline Offline
Send Email Send Email

Forward
Message #44 of 221 |
Expand Messages Author Sort by Date

Hi There, I'm having some trouble with my unix work and was wondering if you could lend me a hand. The main problem has to do with an application called awk. ...
hacker80n
Offline Send Email
Sep 19, 2002
11:24 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help