Question

In: Computer Science

Examine the following shell script and describe its function line-by-line: #! /bin/bash #This script backs up...

Examine the following shell script and describe its function line-by-line:

#! /bin/bash

#This script backs up the Oracle DB

rm -f /SAN/backup-oracle*

if tar -zcvf /SAN/backup-oracle- 'date +%F'.tar.gz/oracledb/*

then

echo "Oracle backup completed on 'date'" >>/var/log/oraclelog

else

echo "Oracle backup failed on 'date'" >>/var/log/oraclelog

mail -s ALERT [email protected] </var/log/oraclelog

fi

Solutions

Expert Solution

#! /bin/bash

#This script backs up the Oracle DB

rm -f /SAN/backup-oracle*

if tar -zcvf /SAN/backup-oracle- 'date +%F'.tar.gz/oracledb/*

then

echo "Oracle backup completed on 'date'" >>/var/log/oraclelog

else

echo "Oracle backup failed on 'date'" >>/var/log/oraclelog

mail -s ALERT [email protected] </var/log/oraclelog

fi

#! /bin/bash

  • That is called a shebang, it tells the shell what program to interpret the script with, when executed.

#This script backs up the Oracle DB

  • This is a comment

rm -f /SAN/backup-oracle*

  • rm command is used to remove files in linux.
  • '-f' option in rm command will remove or delete the files forcefully regardless of its permissions and will also ignore non-existing files.

This will remove the files with name starting with 'backup-oracle' forcefully in the /SAN/ folder

if tar -zcvf /SAN/backup-oracle- 'date +%F'.tar.gz/oracledb/*

  • if the file is found this will work else it will go to else statement.
  • if tar -zcvf /SAN/backup-oracle will compress an entire directory and along with compression it will display the date  shown in YYYY-MM-DD.

echo "Oracle backup completed on 'date'" >>/var/log/oraclelog

  • echo command in linux is used to display line of text/string that are passed as an argument .
  • >> is used to append to files.
  • This command will append ''Oracle backup completed on 'date'" along with date to the file oraclelog in the directory /var/log/.

else

  • If the previous code doesn't work, this code will run.

echo "Oracle backup failed on 'date'" >>/var/log/oraclelog

  • Which will append the line "Oracle backup failed on 'date'" to the oraclelog file in the /var/log/ directory

mail -s ALERT [email protected] </var/log/oraclelog

  • mail command is use to Send mails from command-line.
  • The s option specifies the subject of the mail followed by the recipient email address.
  • This command will send the ALERT to [email protected] and will redirect input to /var/log/oraclelog
  • < is used to redirect input to oraclelog file in the /var/log/ directory

fi will end the if statement

If you have any doubts, leave a comment below before rating. I'll be happy to assist you further.

Do UPVOTE this as I have put a lot of EFFORT in answering this question. It really helps me.


Related Solutions

Examine the following shell script and describe its function line-by-line: #!/bin/bash echo -e "Which file would...
Examine the following shell script and describe its function line-by-line: #!/bin/bash echo -e "Which file would you like to copy> --> \c" echo -e "Which file would you like to copy? --> \c?" read FILENAME mkdir /stuff || echo "The /stuff directory could not be created." && echo "The /stuff directory could not be created." cp -f $FILENAME /stuff && echo "$FILENAME was successfully copied to /stuff"
Simple shell scripting Write a Bash shell script called strcount.sh that counts the number of occurances...
Simple shell scripting Write a Bash shell script called strcount.sh that counts the number of occurances of a given string within a file. The scripts takes two arguments: the name of the file to check and the string to count occurances of. If the file is not found (or not readable), the script should print the error message Cannot access file and exit with code -1. Otherwise, the script should print the number of occurances of the given string and...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all the files in a directory. b. Write a command sequence or a script to insert a line “GHIJKLM” at every 10th line of a file? c. Write a bash command or script to find all the files modified in less than 5 days and print the record count of each.
Linux Sign into your lab account Write a bash shell script that does the following: Print...
Linux Sign into your lab account Write a bash shell script that does the following: Print out a friendly welcome message Ask the user for the name of their favorite animal Grep that animal from a text file noises.txt Tell the user what that animal says (i.e. what noise does it make) If the animal does not exist ask the user what noise the animal makes Store that new information in noises.txt
write a bash shell script using the for-loop construct that counts the number of files and...
write a bash shell script using the for-loop construct that counts the number of files and directories looping through the files in the directory name provided by the user on a prompt by the script and prints "TOO many files" is the count of files is larger than a random number it generates between 20 and 40
Write a bash shell script that takes exactly one argument, a file name. If the number...
Write a bash shell script that takes exactly one argument, a file name. If the number of arguments is more or less than one, print a usage message. If the argument is not a file name, print another message. For the given file, print on the screen its content.
Write a BASH shell script (see the Important Notes section) that acts as a DOS command...
Write a BASH shell script (see the Important Notes section) that acts as a DOS command interpreter (the user enters the DOS command and the script executes the corresponding Linux command). The script should loop continuously until the user enters the QUIT command Prior to accepting a command, display a prompt containing your first name and the greater than symbol (>) Example prompt: linux> The DOS command, and any arguments, should be stored in variables $command – the DOS command...
Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within...
Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within your script  Provide user feedback  Use loops  Use conditionals Remember to use chmod +x to make your file executable! Each script is 5 points in the Specifications portion of the rubric. Don’t forget to maintain good standards and comments. Script 1 – Echo-back some information Write a script name hello.sh that will take the user’s first name as a command line...
Consider the following simple script incorporating a for loop: #!/bin/bash RED='\033[0;31m' NC='\033[0m' clear; cd /home for...
Consider the following simple script incorporating a for loop: #!/bin/bash RED='\033[0;31m' NC='\033[0m' clear; cd /home for DIR in $HOME; do #for DIR in *;do CHK=$(grep -c "/home/$DIR" /etc/passwd) if [ $CHK -ge 1 ] then echo -e "${NC}$DIR is good" else echo -e "${RED}ALERT! $DIR is NOT good!" fi done What kind of script is presented above? How did you make your determination? What is the purpose of the script? In lines #5/6, what is the type of $DIR? In...
What is a working set? What is the first line of every bash script? What is...
What is a working set? What is the first line of every bash script? What is the permission string (RWXRWXRWX format) of the number 311 What is the base directory of a file system called on windows, and on linux What does the term 'super user' mean in terms of operating systems
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT