tailieunhanh - Mastering Unix Shell Scripting p3

% Hậu tố chúng ta có thể ghi đè lên không chỉ là mức độ kích hoạt, nhưng cũng có phương pháp thử nghiệm! Nếu mục nhập chỉ có một số mà không có hậu tố, sau đó mục này trường hợp ngoại lệ tập tin sẽ được bỏ qua và giá trị mặc định của kịch bản sẽ được sử dụng. | File System Monitoring 119 suffix we could override not only the triggering level but also the testing method If an entry has only a number without the suffix then this exceptions file entry will be ignored and the shell script s default values will be used. This suffix method is the most flexible but it too is prone to mistakes in the exceptions file. For the mistakes we need to test the entries in the exceptions to see that they conform to the standard that we have decided on. The easiest way to create this new more robust script is to take large portions of the previous scripts and convert them into functions. We can simply insert the word function followed by a function name and enclose the code within curly braces for example function test_function function_code .Or if you prefer the C-type function method we can use this example test_function function_code . The only difference between the two function methods is one uses the word function to define the function while the other just adds a set of parentheses after the function s name. When we use functions it is easy to set up a logical framework from which to call the functions. It is always easiest to set up the framework first and then fill in the middle. The logic code for this script will look like Listing . load_File_System_data WORKFILE if EXCEPTIONS_FILE exists and is 0 size then load_EXCEPTIONS_FILE_data fi while read WORKFILE which has the filesystem data do if EXCEPTIONS data was loaded then check_exceptions_file RC Get Return code back from function case RC in 1 Found exceeded by method 2 Found out-of-limit by MB Free method 3 Found OK in exceptions file by a testing method 4 Not found in exceptions file esac else No exceptions file Use script defaults to compare fi done if we have anything out of limits then display_output fi Listing Logic code for a large and small filesystem freespace script. 120 Chapter 5 This is very straightforward and easy to do with functions. From this logical .

TỪ KHÓA LIÊN QUAN