Building a bunch of scripts to run.
You will need the os
,re
, and sys
Standard Python Libraries.
Instructors should provide a py_functions.zip
file to help you test your scripts on.
Do your work in a inside the extracted py_functions
directory.
Create a new script for each each task listed below. Test each script in the CLI. For example:
$ python say_my_name.py Snek
# outputs Hello, Snek
read_directory.py
:- Take one argument:
path
. - Print all contents of a directory into stdout.
- DO: Read the
directories
dir provided.
- Take one argument:
read_file.py
:- Take one argument: (path to)
filename
. - Print the buffer/content of that file into stdout.
- DO: Read the
poem.txt
file provided.
- Take one argument: (path to)
make_directory.py
:- Take two arguments:
dirname
andpath
. - Create a directory with the name passed within the path designated in the arguments.
- DO: Build a new directory in the root dir.
- Take two arguments:
make_file.py
:- Take two arguments:
filename
andpath
. - Create a file with the name passed within the path designated in the arguments.
- DO: Make a list file of a topic of your choosing in the root dir. In example,
codenames.txt
- Take two arguments:
append_to_file.py
:- Take two arguments:
path_to_file
andcontent
. - Append new
content
at a file located in thepath
designated in the arguments. - DO: Append some content to the file you made above.
- Take two arguments:
all_dir_count.py
:- Take one argument:
path
(to directory). - Count all directories and their respective subdirectories.
- Print the total count of directories found in designated path into stdout.
- DO: Scan the
directories
dir provided.
- Take one argument:
file_line_count.py
:- Take one argument: (path to)
filename
. - Count all lines in file.
- Print total count of lines into stdout.
- Refactor your script to take in multiple arguments
- Example:
$ python file_line_count.py file1.txt file2.txt file3.txt
- Count all each line in each file.
- Print the total count of lines from all files into stdout.
- Example:
- DO: Scan all the txt files located in the
docs
directory provided.
- Take one argument: (path to)
scan_log_with_keyword.py
- Take three arguments:
path_to_file
,output_filename
andkeyword
. - Scan each line of a log file and only pull out lines that contain the keyword given.
- Print the count of lines that matched into stdout.
- The script should also create a new file with results from the scan with
the name
FILENAME_report.txt
whereFILENAME
is dynamic based on theoutput_filename
argument provided. - DO Logs to scan (in the
logs
dir provided):- In the
nginx.log
grab all the lines with a404
http status code. - In the
auth.log
grabl all the lines with aConnection closed
event. - In the
ufw.log
grab all lines where the source connection came from212.118.253.113
- In the
- Take three arguments: