Download Lab 5 – System Management with Python

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Lab 5 – System Management with Python
Objectives
Automate system management tasks using Python as the scripting language.
Background
There are certain tasks that system administrators will repeat over and over. In order to simplify the
process, automation of system tasks can be done with scripts. Python provides system administrators a
simple to use language for scripting.
Procedures
Part I – Setup Environment
1. Setup a Linux environment for writing Python code. (You should have already done this in Lab 4)
2. Create a new User Account for the system through System->Administration->Users and Groups
Part II – Environment Variables
1. Write a Python script that will display:
a. the current USER from the ENVironment
b. the PATH from the ENVironment
c. the filename of the script
2. Test your script to make sure it works (Hint: take a screenshot for your write-up)
Part III – Copy Files
1. Write a Python script that will copy files from one user’s home directory into another user’s
home directory. Be sure to use a lot of files so that you can have a variety of different file types
and permission settings. (Hint: take a screenshot of the destination directory [ls –l] before and
after transferring the files)
Part IV – Check for Security Holes
1. Write a python script that will search the directory listing (ls –l) for potential security holes by
reviewing the permissions. A security hole means that the file has read, write, or execute
permissions for the group and world users.
2. Generate a message that show the path to the file, who owns the file, and what the permissions
are for both group and world security holes. For example, “File xxxxx owned by yyyyy has rrr,
www, xxx permissions available to the group gggg”.
3. Use the smptlib module to email the results to yourself. You can use your gmail account (it is
free to create one if you don’t have one) for your smtp server. See
http://www.mkyong.com/python/how-do-send-email-in-python-via-smtplib/ (Hint: Take a
screenshot of the email in your inbox)
Pass-off
Be prepared to demonstrate the scripts that you have written.
Write-up instructions
1. Document the lab such that your results could be replicated by another IT student. Include
screenshots.
2. Include your source code. Make sure that your code is well documented.
3. Comment on the extent, advantages, and weaknesses of using a scripting language like Python
for system management.
4. List any references you used, including links to any websites.
Resources



http://pyhton.org/
o http://docs.python.org/library/smtplib.html
http://www.mkyong.com/python/how-do-send-email-in-python-via-smtplib/
http://www.google.com/