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.
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 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
UNIX ONLY Write a bash script that will accept a filename as a command line argument....
UNIX ONLY Write a bash script that will accept a filename as a command line argument. Your script should first check whether the filename has been passed as argument or not (hint: at least one argument has to be provided). If no argument has been provided your script should display appropriate message and exit. If a file name has been provided, your script should check if the file exists in the current directory and display the contents of the file....
write a bash shell program named L1 as follows . L1 expects exactly 2 command line...
write a bash shell program named L1 as follows . L1 expects exactly 2 command line arguments. expects $1 to contain only digits. expects $2 to have exactly 4 characters (can be any character). if NOT exactly 2 command line arguments, echo "need 2 args " and exit. otherwise, if $1 and/or $2 have incorrect value(s) (as above), echo "bad argX", where X is the first incorrect argument, and exit. otherwise, echo "good ". you can use echo,grep, pipe to...
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...
Create a shell script called (Main.sh). The script must call the following scripts (FileS.sh), (Work.sh), (Ether.sh),...
Create a shell script called (Main.sh). The script must call the following scripts (FileS.sh), (Work.sh), (Ether.sh), (Arch.sh) and (Buzz.sh). The first script Main.sh must have two subroutines. The First Subroutine will display the following messages on the screen: 1-Display User login name, date and time. 2-Display System boot time. 3-Working path and Shell type 4-Display Home directory and number of files and directories in your Home. 5-Message describing briefly the requited tasks.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT