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, Snekread_directory.py:- Take one argument:
path. - Print all contents of a directory into stdout.
- DO: Read the
directoriesdir 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.txtfile provided.
- Take one argument: (path to)
make_directory.py:- Take two arguments:
dirnameandpath. - 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:
filenameandpath. - 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_fileandcontent. - Append new
contentat a file located in thepathdesignated 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
directoriesdir 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
docsdirectory provided.
- Take one argument: (path to)
scan_log_with_keyword.py- Take three arguments:
path_to_file,output_filenameandkeyword. - 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.txtwhereFILENAMEis dynamic based on theoutput_filenameargument provided. - DO Logs to scan (in the
logsdir provided):- In the
nginx.loggrab all the lines with a404http status code. - In the
auth.loggrabl all the lines with aConnection closedevent. - In the
ufw.loggrab all lines where the source connection came from212.118.253.113
- In the
- Take three arguments: