Practice Final

Ace your homework & exams now with Quizwiz!

14. Consider the following shell script: #!/bin/bash mkdir /etc/sample 2>/etc/null if [ $? -eq 0 ] then cp -R /etc/hosts /etc/sample echo "successfully copied to /etc/sample" else echo "/etc/sample can not be created" fi Assume you log in as ubuntu (root has r-x on /etc), what would be the output of the script above?

/etc/sample can not be created

$? tells you if a command was successfully executed if $? = ____ then it was successful anything else means something is wrong

0

10. Write the rows you could add to the cron table to schedule the /bin/myscript to run: a) every weekday at 4:00 pm

0 16 * * 1-5 /bin/myscript

10. Write the rows you could add to the cron table to schedule the /bin/myscript to run: b) every Sunday at 10:25 am

25 10 * * 0 /bin/myscript

3. Which kill signal can not be ignored? a. 15 b. 9 c. 1 d. 3

9

For string comparison, use this character ______

=

12. Given the files/dirs and their permissions, answer the following questions: Filename owner group file type+permissions /home/ubuntu/shared computingtech marist drwxrwxrwt /home/ubuntu/shared/file1 bowu marist -rw-rw-r-- /home/ubuntu/shared/file2 roger marist -rw-rw-r— a)Who can create files in the directory shared?

All

9. Assume the following row is added to the cron table. Explain what it does. 30 4 * * 3 /usr/local/sbin/script3.sh

At 4:30 on Wednesdays execute this script

8. Consider the following shell script: echo -e "What is your favorite color? - -> \c" read REPLY if [ $REPLY = "red" -o $REPLY = "blue" ] then echo "The answer is red or blue" else echo "The answer is not red nor blue" fi What would be displayed if a user executes the above program and answered Blue when prompted? a. The answer is red or blue b. The answer is not red nor blue c. The code would cause an error d. The answer is red or blue The answer is not red nor blue

B Linux is case sensitive

6. Which of the following operators reverses the meaning of a condition? a. -o b. -a c. ! d. #!

C

7. What does >> accomplish when entered on the command line after a command? a. It redirects both Standard Error and Standard Output to the same location b. It does not accomplish anything c. It redirects both Standard Error and Standard Input to the same location d. It appends the Standard Output to a file

D

15. Consider the following shell script var_change.sh: #!/bin/bash echo "var1 is $var1 : var2 is $var2" var1='local 1' var2='local 2' echo "var1 is $var1 : var2 is $var2" var1='changed again' var2='changed again' echo "var1 is $var1 : var2 is $var2" Assume var_change.sh is executable and located in the current directory. Predict the output of the following commands executed in the shell. var1='global 1' var2='global 2' export var1 export var2 ./var_change.sh echo var1 is $var1: var2 is $var2 What is the output of the THIRD echo statement? var1 is _____ : var2 is _____

changed again changed again

17. Complete the following shell script that deletes files in a given directory that contains more than a given number of characters. The shell script asks the user to enter a directory (DIR), and a size (SZ: number of characters). Then underneath the given directory, • If a file is a directory, then ignore that file and continue processing with the next file in the directory. • If a file is a regular file (i.e., not a directory), then if it contains more than SZ characters it should be deleted. #!/bin/bash echo -e "What directory has the files you would like to process?--> \c" read DIR echo -e "What is the maximum size (number of characters) allowed in the directory?--> \c" read SZ # complete the shell script from here Hint: Use wc -c to count the number characters in a file

echo -e "What directory has the files you would like to process?--> \c" read DIR echo -e "What is the maximum size (number of characters) allowed in the directory?--> \c" read SZ # complete the shell script from here for file in $DIR/* do if [ -f $FILE ] then COUNT=$(cat $file | wc -c) if [ $COUNT -gt $SZ ] then rm $file echo "$file was removed" else echo "the file was not removed" fi fi done

15. Consider the following shell script var_change.sh: #!/bin/bash echo "var1 is $var1 : var2 is $var2" var1='local 1' var2='local 2' echo "var1 is $var1 : var2 is $var2" var1='changed again' var2='changed again' echo "var1 is $var1 : var2 is $var2" Assume var_change.sh is executable and located in the current directory. Predict the output of the following commands executed in the shell. var1='global 1' var2='global 2' export var1 export var2 ./var_change.sh echo var1 is $var1: var2 is $var2 What is the output of the FOURTH echo statement? var1 is _____ : var2 is _____

global 1 global 2

11. Write the test statement (the condition for the if statement in a shell script) that can be used to test the following scenarios: a. The variable SCORE is between 60 and 70

if [ $SCORE -gt 60 -a -lt 70 ]

11. Write the test statement (the condition for the if statement in a shell script) that can be used to test the following scenarios: b. The variable TEST are equal to "success"

if [ $TEST = "success" ]

Write the test statement (the condition for the if statement in a shell script) that can be used to test the following scenarios: c. The file /etc/hosts exists and is not a directory

if [ -f /etc/hosts ]

15. Consider the following shell script var_change.sh: #!/bin/bash echo "var1 is $var1 : var2 is $var2" var1='local 1' var2='local 2' echo "var1 is $var1 : var2 is $var2" var1='changed again' var2='changed again' echo "var1 is $var1 : var2 is $var2" Assume var_change.sh is executable and located in the current directory. Predict the output of the following commands executed in the shell. var1='global 1' var2='global 2' export var1 export var2 ./var_change.sh echo var1 is $var1: var2 is $var2 What is the output of the SECOND echo statement? var1 is _____ : var2 is _____

local 1 local 2

2. Each process has a process ID and a : a. child process b. daemon c. parent process ID

parent process ID

1. Which command entered without arguments is used to display a list of processes running? a. ppid b. list c. pid d. ps

ps

14. Consider the following shell script: #!/bin/bash mkdir /etc/sample 2>/etc/null if [ $? -eq 0 ] then cp -R /etc/hosts /etc/sample echo "successfully copied to /etc/sample" else echo "/etc/sample can not be created" fi a) Assume you log in as root (root has rwx on /etc), what would be the output of the script above?

successfully copied to /etc/sample

4. Which command can be used to know the total number of processes/tasks on the Linux system? a. ps -el b. top c. ps d. ps -f

top

12. Given the files/dirs and their permissions, answer the following questions: Filename owner group file type+permissions /home/ubuntu/shared computingtech marist drwxrwxrwt /home/ubuntu/shared/file1 bowu marist -rw-rw-r-- /home/ubuntu/shared/file2 roger marist -rw-rw-r— b) Who can edit file1?

user bowu group marist

5. How do you indicate a comment line in a shell script? a. There are no comment lines in a shell script b. Begin the line with # ! c. Begin the line with ! d. Begin the line with #

D

Sticky Bit

In order to rename or remove a file you must be either owner of the file or owner of the directory

12. Given the files/dirs and their permissions, answer the following questions: Filename owner group file type+permissions /home/ubuntu/shared computingtech marist drwxrwxrwt /home/ubuntu/shared/file1 bowu marist -rw-rw-r-- /home/ubuntu/shared/file2 roger marist -rw-rw-r— c)Who can rename file1?

User bowu group marist

12. Given the files/dirs and their permissions, answer the following questions: Filename owner group file type+permissions /home/ubuntu/shared computingtech marist drwxrwxrwt /home/ubuntu/shared/file1 bowu marist -rw-rw-r-- /home/ubuntu/shared/file2 roger marist -rw-rw-r— d) Who can remove file1?

User bowu group marist

15. Consider the following shell script var_change.sh: #!/bin/bash echo "var1 is $var1 : var2 is $var2" var1='local 1' var2='local 2' echo "var1 is $var1 : var2 is $var2" var1='changed again' var2='changed again' echo "var1 is $var1 : var2 is $var2" Assume var_change.sh is executable and located in the current directory. Predict the output of the following commands executed in the shell. var1='global 1' var2='global 2' export var1 export var2 ./var_change.sh echo var1 is $var1: var2 is $var2 What is the output of the FIRST echo statement? var1 is _____ : var2 is _____

global 1 global 2


Related study sets

Ch 4 Foundations of Organizational Change

View Set

Musculoskeletal System Physical Assessment- Chapter 22

View Set

Mulesoft - Associate / Development Fundamental

View Set

Chapter 36 Adrenocortical Agents PrepU

View Set

Chapter 14—Sexual Difficulties and Solutions Iclicker questions

View Set

EV Intro to Comms. & Speech: Understanding Nonverbal & Verbal Messages; Unit Review & Test

View Set