Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. The lab work consists of all practical tasks which must be submitted via Moodle.
  2. You must submit the following:
  3. A single zip file, uploaded to Moodle.
  4. Note: Each Lab session is worth 1% of your final mark
  5. Learning Outcomes Assessed
  6. The following learning outcomes are being assessed in this lab session:
  7. Use the command-line on a UNIX system
  8. Manage a Linux server system (including files, processes, users)
  9.  
  10.  
  11. Lab 8 – Practical tasks
  12.  
  13. Create a script findBigFiles that will take as an argument:
  14. The size in MB that is considered to be a big file.
  15.  
  16. The script will return the following information for the current working directory ($pwd):
  17. The list of large files
  18. The number of files found
  19. The date and time of the search
  20.  
  21. Breakdown of Tasks
  22. Add comments (script name, author, date and purpose) at the start of your script as appropriate
  23. Create a function usage that will print out the correct usage as shown below
  24.  
  25. ***************************************
  26. USAGE: $SCRIPT_NAME [Number_Of_Meg_Bytes]
  27. EXAMPLE: $SCRIPT_NAME 5
  28. Will Find Files Larger Than 5 Mb in and below the Current Directory...
  29.  
  30. EXITING...
  31. **************************************
  32.  
  33. 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.
  34. Hint:
  35. To exit the script (i.e. if the number of arguments is incorrect), use the command exit 1
  36.  
  37. In order to allow the user to exit using CTRL+C, we need to add the following code.
  38. In the FUNCTION section:
  39. function trap_exit
  40. {
  41. echo -e “\n**********************************************”
  42. echo -e “\n\n EXITING ON A TRAPPED SIGNAL...”
  43. echo -e “\n\n**********************************************\n”
  44. }
  45. At the start of the MAIN section:
  46. # Set a trap to exit. REMEMBER - CANNOT TRAP ON kill -9
  47. trap ‘trap_exit; exit 2’ 1 2 3 15
  48.  
  49. Note the use the command exit 2 to indicate a forced exit
  50.  
  51. Define the following variables and assign to them the appropriate value
  52. DATESTAMP is the current date/time in the following format “%h %d,%Y,%T”
  53. SEARCH_PATH is the current directory (Top-level directory to search)
  54.  
  55. Display the following message on screen
  56.  
  57. Searching for Files Larger Than xMb starting in:
  58. /home/A2009XXXX
  59. Please Standby for the Search Results...
  60.  
  61. Be sure to use the correct variables and parameters.
  62.  
  63. Searching for files
  64. 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.
  65. Hint: in the man find out about –type, -size and –print
  66. Redirect the output to a file (For example: results.out)
  67.  
  68. Test the size of the file to find out if there is anything inside of it
  69. Hint: -s checks the size of a file
  70.  
  71. If the file is empty, display the following info on screen:
  72. Nofiles were found that are larger than xMB
  73. Exiting...
  74.  
  75. If the file is not empty, then the file contains one line per file.
  76. Count the number of lines in the file and display as follows:
  77. Number of files found: 17
  78.  
  79. The output should display as follows:
  80. Searching for Files Larger Than 1Mb Starting in:
  81.  
  82. /home/david/unit_8
  83.  
  84. Please Standby for the Search Results...
  85.  
  86. Date and time of Search: Dec12,2011,15:32:58
  87.  
  88. Number of Files Found: 3
  89.  
  90. These files were found:
  91. /home/david/unit_8/CPU.JPG
  92. /home/david/unit_8/findbigfiles
  93. /home/david/unit_8/findbigfiles_new
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. Zip the script and upload it to Moodle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement