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"
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.
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.
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
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt...
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt the user to "Enter a number between 1 and 10". (Hint: Use the 'echo' and 'read' commands in the script. See the slide about the 'read' command) If the number is less than 5, print "The number is less than 5" (Hint: You will read input into a variable; e.g. read NUM. In the IF statement, enclose $NUM in quotes; e.g. "$NUM". Also, remember...
Assignment Write a network diagnostics bash script that does the following: Finds the IPv4 address of...
Assignment Write a network diagnostics bash script that does the following: Finds the IPv4 address of the default gateway on your machine (one way to get this is the 'default' entry, also shown as 0.0.0.0, in the output of 'ip route') and runs a ping (with a count of 5 pings) to it. Runs another count of 5 pings to the site example.com. Outputs a 1-line summary of interfaces on your machine, not including the loopback address (lo). Outputs a...
Please answer the following using bash shell. 1. The students.txt file consists of rows of students...
Please answer the following using bash shell. 1. The students.txt file consists of rows of students where each row contains a student’s first name, last name, major, and 5 test scores. Write a script that uses a while read statement to input all of the students, line by line, computes the average test score and determines the letter grade for that student. Of the 5 test scores, the 5th test is worth double so that you add each test score...
Describe in words what the function of each line is in the following SQL query The...
Describe in words what the function of each line is in the following SQL query The lyrics database is provided under question 3 for context 1. select studioID, studioname, base from salespeople sa inner join studios st on (sa.salesID = st.salesid) where base < 300 2. SELECT artistName FROM Artists WHERE artistID IN (SELECT artistID FROM Titles) 3. select m.lastname, m.firstname, s.lastname         from members m inner join salespeople s using (salesID)         order by m.lastname asc; The lyrics database...
Create shell scripts, each in its own .sh file. Please include a shebang line at the...
Create shell scripts, each in its own .sh file. Please include a shebang line at the top of the script as well as appropriate comments through out. Write a script that reads sunspot data from data-shell/data/sunspot.txt and uses awk to print a list of the total number of sunspots for each year on record as well as the twelve monthly averages across the record. Note: "awk allows you to index arrays using strings, so as you traverse the data file,...
Linux Question: Describe how you created above file and its contents in VI. a) Bash/VI commands:...
Linux Question: Describe how you created above file and its contents in VI. a) Bash/VI commands: 20pts; b) Non-brute-force solution: 10pts). Note: Brute-force solution means that entering characters one by one Install JDK 1.8 by the following command: $ sudo dnf –y install java-1.8.0-openjdk-devel.x86_64 Use VI to create a file “YourFirstNameHomework.java” (e.g., “MollyHomework.java”) and add the following contents into it. (grading details: file name format:10 pts, a screenshot of the file content in the VI environment: 10pts, paragraphs: 10pts, empty...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT