Working with Shells Homework 1
Create a directory called shell_hwk_1 and place the following files in that directory. Then, tar that directory and upload it to moodle. ($ tar -cvf shellHwk1.tar shell_hwk_1; then view it with $ tar tvf shellHwk1.tar)
1. Create one alias you would find useful. An alias is a definition of a command that you can type the alias to execute the command. Add it to your .bashrc file. Source it with . .bashrc, and then copy that file to your shell_hwk_1 directory. (To see the .bashrc file, you will need to use ls -a. If you do not have a .bashrc file, you can create it. Remember the name has a dot immediately before the b.)
2. Create a script that will allow you to compile a single c file by just having a parameter of the program name. It should take the program name and put it into the command: gcc givenFilename.c -o givenFilename -g . (If you want, you can also let it pass a few other parameters so that it can accomodate added options such as -lm). Place it in the bin directory inside your home directory and make it executable. Test it. Then copy it into your shell_hwk_1 directory. (If you do not have a bin directory, create it using mkdir.)
3. Create a script that will list all the users who have been on the system since the system log was last cleared. The Linux command 'last' lists users in reverse chronological order. Use this together with sort, sed and uniq to get a listing of all the users who have been on the system since the log was last cleared. (Hint: use sed to get rid of everything on the line other than the login name). Place it in the bin directory inside your home directory and make it executable. Test it. Then copy it into your shell_hwk_1 directory.
4. Upload or type the file below into your shell_hwk_1 directory. Note that the fields are all separated by a comma and that the first name comes first, last name next but that the birth date or email comes in any order. The birth date always has the format MM-DD-YYYY. Make a script that prints out the first name, last name and birthdate for a certain last name. Place it in the bin directory inside your home directory and make it executable. Test the script with Sawyer, then Jones and then Green. Then copy it into your shell_hwk_1 directory.
Amy,Sawyer,01-05-2000,yyy@hames.com
Sally,Sawyer,zzz@jooo.com,01-20-1970
Tom,Sawyer,05-31-1901,yyz@x.com
Sally,Jones,06-22-1950,yyyy@fov.com
Sawyer,Jones,07-06-1968,ysidd@fov.com
Betsy,Sawyer,06-23-1995,bets@x.com
Hints on #4:
You can use this sed expression: sed -rn /$name/s/\([^,]*\),\([^,]*\),.*\([0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]\).*/\\1,\\2,\\3/p nameList
(I am assuming you put the data above into nameList.) Note that I used \ before ( ) and \ to keep the shell from using them as other commands.
How do you set up the script to read the $name varaible from the screen?
Sample Run of this program 3 times, once with Jones, Sawyer and Green:
PEPPER>./spieg2.sh
enter name to find
Jones
Sally,Jones,06-22-1950
Sawyer,Jones,07-06-1968
PEPPER>./spieg2.sh
enter name to find
Sawyer
Amy,Sawyer,01-05-2000
Sally,Sawyer,01-20-1970
Tom,Sawyer,05-31-1901
Sawyer,Jones,07-06-1968
Betsy,Sawyer,06-23-1995
PEPPER>./spieg2.sh
enter name to find
Green