Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This problem is to be solved in linux command line. Task 3. bash script named sc

ID: 3753522 • Letter: T

Question

This problem is to be solved in linux command line.

Task 3. bash script named script2 The name of your bash script must be script2 and below is a description of what it should do when executed 1. All displayed messages must be exactly as shown here, with all details. All commands must follow the order described below 2. The scripts displays creating MY_DIR and creates a directory named MY_DIR in the current directory 3. The scripts displays creating MY_FILE in MY_DIR and creates a file named MY_FILE in the directory MY DIR. The content of the file MY FILE is a single line MY FILE ***. 4. Then the script displays the line MY_DIR: followed by the contents of the directory 5. Then the script displays a line MY_FILE: followed by the contents of the file MY_FILE 6. Then the script stores in a variable a string obtained by piping the output of Is -la to grep applied to MY DIR . The first 10 letters of the string contain the permissions for the directory. Play with Is -la MY_DIR to see what it produces. To store the result of ls -la | grep MY_DIR in a variable var use var-Is -la | grep MY_DIR (note the back quotes!). To extract the first 10 characters from the string in var for the use in echo in the next step, use Sivar:0:10) 7. Then the script displays a single line original permissions of MY_DIR: xxx where xxx is the permissions (the permissions must be obtained from the directory, not hard coded in the script !!!) 8. Then the script displays line change it to drwxrwxrwx and using chmod it changes the permissions to the desired combination. Then as in 6. and 7. , it displays a line containing new permissions of MY_DIR: xxx where xxx is the changed permissions (the permissions must be obtained from the directory, not hard coded in the script !!!) 9. Then the script displays line change it to drwx--x--x and using chmod it changes the permissions to the desired combination. Then as in 6. and 7. , it displays a line containing new permissions of MY_DIR: xxx where xxx is the changed permissions (the permissions must be obtained from the directory, not hard coded in the script!!!) 10. Then the script displays line change it to drwxrrand using chmod it changes the permissions to the desired combination. Then as in 6. and 7. , it displays a line containing new permissions of MY_DIR: xxx where xxx is the changed permissions (the permissions must be obtained from the directory, not hard coded in the

Explanation / Answer

if [ -d "MY_DIR" ]
then
rm -rf MY_DIR;
fi

echo "creating MY_DIR";
mkdir MY_DIR;

echo "creating MY_FILE in MY_DIR";
echo "*** MY_FILE ***" >> MY_DIR/MY_FILE;

echo "MY_DIR:"
ls MY_DIR;
echo "MY_FILE:"
cat MY_DIR/MY_FILE;

var=`ls -la|grep MY_DIR`
echo "Original permissions of MY_DIR : ${var:0:10} "

echo "change it to drwxrwxrwx"
chmod ugo=rwx MY_DIR
var=`ls -la|grep MY_DIR`
echo "new permissions of MY_DIR : ${var:0:10} "

echo "change it to drwx--x--x"
chmod u=rwx,g=x,o=x MY_DIR
var=`ls -la|grep MY_DIR`
echo "new permissions of MY_DIR : ${var:0:10} "

echo "change it to drwxr--r--"
chmod u=rwx,g=r,o=r MY_DIR
var=`ls -la|grep MY_DIR`
echo "new permissions of MY_DIR : ${var:0:10} "

echo "trying to remove MY_DIR by rmdir";
rmdir MY_DIR;

echo "trying to remove MY_DIR by rm";
rm MY_DIR;

echo "trying to remove MY_DIR by rm -r";
rm -r MY_DIR;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote