-------------------------- Practice Unix/Linux Script - differ.sh -------------------------- -IAN! idallen@ncf.ca All scripts written must conform to the script_checklist.txt checklist. All user input (arguments or via "read") must be validated before being used. Do not process bad or missing input data! Write an executable shell script named differ.sh that will do the following actions (in the order given below): 1. Verify that there are more than zero command line arguments; otherwise, exit with an error message. (i.e. Exit if there are zero arguments.) 2. Put the first argument (a file name) into a variable named filnam. 3. If there is only one command line argument, prompt the user to enter the missing directory name and read the name from standard input. Put the directory name (either the second command line argument or what the user entered from standard input) into the variable dirnam for use in the rest of the script. 4. Display this exact sentence: You are processing file 'XXX' and directory 'YYY'. where XXX is the contents of the filnam variable and YYY is the contents of the dirnam variable containing the directory name that the user specified. Use the exact punctuation. 5. Verify that the path named by the dirnam variable is a directory; otherwise, exit with an error message. (i.e. Exit if the path is not a directory.) 6. Verify that the path named by the dirnam variable is writable; otherwise, exit with an error message. (i.e. Exit if the directory is not writable.) 7. Verify that the path named by the dirnam variable is searchable; otherwise, exit with an error message. (i.e. Exit if the directory is not searchable.) 8. Put the file pathname $dirnam/$filnam into a variable named diffout. (Do not create this file yet.) 9. Verify that the file named by the diffout variable is zero size or nonexistent; otherwise, exit with an error message. (i.e. Exit if non-empty.) 10. Make up a pathname for a temporary file and put it into a variable named tfile. Use the process ID of the current process in the pathname. The pathname of the temporary file should be under the /usr/tmp directory. (Do not create the file yet.) 11. Sort the password file and place the output into the temporary file named by the tfile variable. Exit with a non-zero exit status if the command fails. 12. Generate the lines of difference between the contents of the password file and the contents of the temporary file and put the resulting output into the file named by the diffout variable. 13. Save the exit status of the difference command in a variable named dstat. 14. If the size of the file named by the diffout variable is greater than zero, append this exact message to the file named by the diffout variable: Difference exit status was XXX. where XXX is the contents of the dstat variable from a previous step. Exit with a non-zero exit status if the appending command fails.