CSCI 257: Fundamental UNIX System Administration
Class Project for Spring 2003
The goal of the class project is to provide students with practical experience
to administer Linux installation and administration on a computer shared
with Windows.
Laboratory Assignment 4
ASSIGNMENT DUE: 12:00 NOON, March 12, 2003.
Assignment Description:
As a system administrator you will need to do various jobs such as manage
file permissions, understand how to get information about your system and
use scripting to automate tasks.
Goal:
The goal of this assignment is to introduce students
to /proc, file permissions, and some shell features.
Objectives:
- Explore /proc a little more.
- Searching for files on your system (grep, find, and locate).
- Learn how to use chmod to change permissions on files
- Learn how to use chown to change file ownership
- Learn about the sticky bit and the SUID and GUID bits
- Learn a little about the bash shell
- Learn some scripting basics
Expected Outcome:
- TURN-IN
- Students will perform the exercises listed and provide answers
- Students will create a custom .bashrc file as described below and
turn it in
- Students will write the getinfo script described below and
turn-in a printout
Generic questions to find out what kind of system you are doing you work
on
- What distribution and version of Linux are you using?__________________________________
- Do you have X configured on this system?____________________________________________
- Do you have internet access on this system under Linux?_________________________________
- What shell are you using (bash is the Linux default, type echo
$SHELL )?__________________
Examining /proc a little more (you might need to su to root to do some
of this stuff).
- Change to the /proc directory and view the output of ls
- View the output of cat /proc/cpuinfo
- What is the processor number (the first line)?_________________
- What is the "model name"?________________________________
- What about the cache size?________________________________
- View the output of ls -l /proc/kcore ( /proc/kcore
gives you a window into the memory on your computer, so you can actually
view the contents of memory if you cat this file).
- Notice the file size of this file tells you how much RAM you have
on the system in bytes.
- How many bytes of RAM does your system have according to a long
listing of kcore?___________________________
- Use mathematics to calculate the number of bytes of RAM your
system should have? (My computer has 256MB so I do the following multiplication:
256 * 1024 * 1024 = 268435456 bytes)______________________________________
- Does kcore and your math give the same result?___________________________
- View the output of cat /proc/meminfo
- How much is swap being used or is it all free?___________________________________
- What version of gcc is on your system (cat /proc/version)?____________________________
- View the output of cat /proc/interrupts
- The left most column gives you the interrupt number 0-15, the
next column is a counter of how many times that interrupt has been called,
and the right most column tells you the driver that is calling the interrupt
- What is the interrupt for the timer (0-15)?______________________
- What is the interrupt for the keyboard (0-15)?_________________________
- What is the watch command for (type whatis watch)?________________________________________________________________
- Now view the output of watch -n1 cat /proc/interrupts
- What does the counter for the keyboard interrupt read?_________________________
- Hold down some key like "f" for a few seconds and watch the interrupt
counter for the keyboard increase.
- Next try tapping one key like "f" only occasionally to see how
much the interrupt counter increases with each key press. How much
does it increase with one key press?________________________________
- What does the -n1 option do (type man watch if you
aren't sure)?)___________________________________
- View the output of cat /proc/partitions to see what partitions
you have on your system. Compare it to the output of the command df.
Next type the command mount with no options and view its output.
- Change to the directory /proc/1 this directory contains information
about process with ID 1
- View the output of cat environ | tr '\0' '\n' to learn
something about this programs environment
- What is its home directory?______________________
- What happens when you just cat environ?_____________________
- What does the command tr do?______________________________
- View the output of cat status
- What is the name of this process?_____________________________
- What state is it in?_________________________________________
- View the output of the command scanpci -v | more
- How many times do you see "card unknown" or "device unknown"?______________________________
- Compare the output of scanpci -v | more to the output of
cat /proc/pci, similar?__________________________________________
- Also view the output of lspci, similar?______________________________________________________
Searching (you might need to su to root to do some of this stuff).
(When you su to root you might need to type "su -" so that your PATH
gets set up right. Adding the dash makes it behave as a login shell).
- The grep command
- Search /etc for files containing your username, in my case I would
type grep "todd" /etc/*
- What files have your user name in them?________________________________________________
- Do the search again but this time recursively search within all
directories found inside /etc, in my case I would type grep -r "todd"
/etc/*
- Name any additional files with your username in them (or say
none)?_____________________________ ______________________________________________________________________________________
- This time just search the passwd file for your username, in my
case I would type grep "todd" /etc/passwd
- What is the output?______________________________________________________________________
- The find command can be used to find files matching all
sorts of different criteria
- Use the command find / -name "*syslog*" to find all of
the files and directories on your system with "syslog" somewhere in the
name (This may take awhile).
- Now try find / -name syslog
- What were the results this time?____________________________________________________________
- Use the command find / -path "*doc*bash*" to find files
and directories whose full path includes the term "doc" followed by "bash"
in some manner.
- Finding setuid files
- Run the command find / -perm -u+s to list files with
the setuid bit set
- Name 5 of the results:________________________________________________________________
- The locate command
- View the man page for the commands locate and updatedb
- If your system doesn't have a locate database built you will need
to run the command updatedb as root
- Type the command locate syslog | nl
- How many results were returned from this command?_____________________________________
- Where is the syslogd configuration file on your system?____________________________________
(If you aren't sure from the output read the man page for syslogd).
- Notice how much faster locate is than find, also note that
locate uses a database for finding files so if the database is out of date
it won't be much help for finding newly created files.
- As a normal user run the command locate root | nl. How
many results were returned?_________________
- Now su to root and run the same command locate root
| nl. How many results this time?_______________
- The whereis command
- What does whereis tell you (type whatis whereis)?_____________________________________________
- Type the command whereis grub. What directory is
grub in?_______________________
- Type the command whereis lilo. What directory is
lilo in?__________________________
- Type the command whereis whereis. What directory is whereis
in?___________________
- The which command
- What does which tell you (type whatis which)?_________________________________________________
- Type the command which ls. What directory is ls
in?____________________________
- The type command
- Type the command type ls. What is the output?________________________________________________
- Type the command type cd. What is the output?________________________________________________
- Type the command type vi. What is the output?________________________________________________
Permissions
- Give the chmod command to change permissions on file1
to give:
- Owner - read write execute
- Group - read write
- Other (or world) - read only
- $___________________________________________________________________
- Give the chmod command to change permissions on file2
to give:
- Owner - read execute
- Group - read execute
- Other - no permissions
- and set the setuid bit
- $___________________________________________________________________
- Give the chmod command to change permissions on file3
to give:
- Owner - read write execute
- Group - read execute
- Other - execute
- $___________________________________________________________________
- Give the chmod command to add read permission for the group
ownership of file4 but without modifying other existing permissions:_____________________________________________________________________________
- What is chown used for?______________________________________________________________________
Shell Features and Customization (this doesn't go into everything but
at least it's a start)
- Change to /usr on your system
- Use ls to see the directory listing
- Next type echo *
- Describe the output of echo * ?_____________________________________________________________
- Next type echo "*"
- What was the output of echo "*" ?__________________________________________________________
- Set a variable called SOMEVAR, type SOMEVAR=/etc
- Now try cd SOMEVAR and cd $SOMEVAR to see what one
will take you to /etc
- Which one took you to /etc?______________________________________________
- What does echo SOMEVAR give you as output?__________________________________
- What does echo $SOMEVAR give you as output?_________________________________
- What does echo $SHLVL give you as output?_____________________________________
- Now start a subshell by typing bash
- Now what does echo $SHLVL give you as output?____________________________________
- Now what does echo SOMEVAR give you as output?__________________________________
- Now what does echo $SOMEVAR give you as output?_________________________________
- Next exit your subshell by typing exit
- Turn SOMEVAR to an environmental variable by typing export
SOMEVAR
- Once again start a subshell by typing bash
- Now what does echo SOMEVAR give you as output?__________________________________
- Now what does echo $SOMEVAR give you as output?_________________________________
- Next exit your subshell by typing exit
- You can see what your environment is by typing printenv (or
env)
- How many environmental variables are currently set, type printenv
| nl ?___________________________________
- Set a variable called SOMEVAR2, type SOMEVAR2=/bin
- How many environmental variables are set now, type printenv |
nl ?_______________________________________
- You can unset these variabls by typing unset SOMEVAR SOMEVAR2
- Now how many environmental variables are set, type printenv |
nl ?_______________________________________
- Bash has some built-in shell variables, here are a couple
- What is the output of the following:
- echo $SECONDS _________________________________________
- echo $BASH _____________________________________________
- echo $PWD ______________________________________________
- echo $BASH_VERSION ___________________________________
- There are some config files for bash that may exist in your
home directory
- Which of the following exist in your home directory, type ls
-a ~
- If both .profile and .bash_profile exist in your home directory
only one gets run when you create a login shell.
- If one or both of these files does not exist create them. Next
edit your either your existing files or newly created files to add the lines
echo "this is .bash_profile" and echo "this is .profile"
respectively. Now you can create a login shell to see which
gets ran by typing bash --login
- If both of these files exist which one gets ran?________________________________________________
- How would you redirect the output of the date command to a
file named date.txt?________________________________
- How would you append the output of the date command to a file
named file1?___________________________________
(give the actual command for these).
- Use the cut command on the output of a long
directory listing in order to display only the file permissions. Then pipe
this output to sort and uniq
to filter out any double lines. Then use the wc
to count the different permission types in this directory. The output
should be a number on a single line only. Once you figure it out give
exactly what you would type to do this in one line. __________________________________________________________________________________
(read the man pages for these commands, the answer will look something
like: cmd -options | cmd -options | cmd | cmd ...)
(when I did this on my system I counted 2 extra lines, a blank line and a
line with "total" in it, these were from the output of ls -l, don't worry
about whether or not lines like this these are counted).
- Create your own .bashrc file
- Include at minimum the following personal customizations (make sure
they all work)
- A comment with YOUR NAME
- Create at least 3 or 4 aliases
- Set your umask to some value
- Set PS1 (the variable that defines your prompt) to something
- print out your file and turn it in with this lab
Write a Basic Script
- Write a script called getinfo
- This script will take one command line argument which will be
the name of a program (additional arguments can be ignored).
- This script will then run whatis, whereis and type
-a providing the same argument that was passed to the script getinfo.
Here is an example where I call getinfo on my computer three different
times:
todd@sophia:~$ ./getinfo type
type [builtins] (1) - bash built-in commands, see bash(1)
type: /usr/share/man/man1/type.1.gz
type is a shell builtin
todd@sophia:~$ ./getinfo ls
ls (1) - list directory contents
ls: /bin/ls /usr/share/man/man1/ls.1.gz
ls is /bin/ls
todd@sophia:~$ ./getinfo cd
cd [builtins] (1) - bash built-in commands, see bash(1)
cd (n) - Change working directory
cd: /usr/share/man/man1/cd.1.gz /usr/share/man/mann/cd.n.gz
cd is a shell builtin
- When getinfo is called with no arguments it will print
the usage message as below:
todd@sophia:~$ ./getinfo
Usage: getinfo COMMANDNAME
please try again...
- (Notice that when getinfo was called without any arguments there
was no additional error messages (for example, "usage: whatis keyword ..."
or "whereis [ -sbmu ] [ -SBM dir ... -f ] name..."). Therefore this
script will need to check that it was called with at least one command
line argument.
- I recommend writing this script using bash but you can
use any of the following if you prefer sh, csh, tcsh,
ksh. or perl.
- To run the script you will need to have execute permission on it
and have it in your PATH (or give the path like I did above ./getinfo).
- Please include one line of documentation
- # getinfo script - written by YOUR NAME
- (You can document it more if it helps you but one line similar
to above is all I care about).
- Include a print out of this script with your turn-in