Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The lab work consists of all practical tasks which must be submitted via Moodle.
- You must submit the following:
- A single zip file, uploaded to Moodle.
- Note: Each Lab session is worth 1% of your final mark
- Learning Outcomes Assessed
- The following learning outcomes are being assessed in this lab session:
- Use the command-line on a UNIX system
- Manage a Linux server system (including files, processes, users)
- Lab 8 – Practical tasks
- Create a script findBigFiles that will take as an argument:
- The size in MB that is considered to be a big file.
- The script will return the following information for the current working directory ($pwd):
- The list of large files
- The number of files found
- The date and time of the search
- Breakdown of Tasks
- Add comments (script name, author, date and purpose) at the start of your script as appropriate
- Create a function usage that will print out the correct usage as shown below
- ***************************************
- USAGE: $SCRIPT_NAME [Number_Of_Meg_Bytes]
- EXAMPLE: $SCRIPT_NAME 5
- Will Find Files Larger Than 5 Mb in and below the Current Directory...
- EXITING...
- **************************************
- In the main part of your script, test the number of arguments so that if the script does not have 1 argument, it prints the usage and exits.
- Hint:
- To exit the script (i.e. if the number of arguments is incorrect), use the command exit 1
- In order to allow the user to exit using CTRL+C, we need to add the following code.
- In the FUNCTION section:
- function trap_exit
- {
- echo -e “\n**********************************************”
- echo -e “\n\n EXITING ON A TRAPPED SIGNAL...”
- echo -e “\n\n**********************************************\n”
- }
- At the start of the MAIN section:
- # Set a trap to exit. REMEMBER - CANNOT TRAP ON kill -9
- trap ‘trap_exit; exit 2’ 1 2 3 15
- Note the use the command exit 2 to indicate a forced exit
- Define the following variables and assign to them the appropriate value
- DATESTAMP is the current date/time in the following format “%h %d,%Y,%T”
- SEARCH_PATH is the current directory (Top-level directory to search)
- Display the following message on screen
- Searching for Files Larger Than xMb starting in:
- /home/A2009XXXX
- Please Standby for the Search Results...
- Be sure to use the correct variables and parameters.
- Searching for files
- Use the find command to find all the files greater than xMB (the size of MB is passed from an argument) in your current directory.
- Hint: in the man find out about –type, -size and –print
- Redirect the output to a file (For example: results.out)
- Test the size of the file to find out if there is anything inside of it
- Hint: -s checks the size of a file
- If the file is empty, display the following info on screen:
- Nofiles were found that are larger than xMB
- Exiting...
- If the file is not empty, then the file contains one line per file.
- Count the number of lines in the file and display as follows:
- Number of files found: 17
- The output should display as follows:
- Searching for Files Larger Than 1Mb Starting in:
- /home/david/unit_8
- Please Standby for the Search Results...
- Date and time of Search: Dec12,2011,15:32:58
- Number of Files Found: 3
- These files were found:
- /home/david/unit_8/CPU.JPG
- /home/david/unit_8/findbigfiles
- /home/david/unit_8/findbigfiles_new
- Zip the script and upload it to Moodle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement