Changes

Jump to: navigation, search

OPS245 Scripting Exercises Lab 2 dev

38 bytes added, 08:59, 26 January 2023
Virtual Machine Backup Script
= Virtual Machine Backup Script === Key Concepts ===== Conditional Logic ===
Condition Logic aka Control Flow statements aka If statements are an important scripting and programming concept. They allow us to make scripts more flexible by building in decision making. You learned how to use these in BASH scripting in ULI101, but lets review the basics. You use an if statement to check whether a condition is met (or not, depending on how you write it) and execute some code (or not) based on that condition. Here is a sample if statement in Bash:
<pre>
</pre>
=== To do : sample Bash script ===
* Copy the above code and give it execute permission using the chmod command.
* Try running it as a regular user. What happens?
</pre>
=== To do : sample Python script ===
* Copy the above code and give it execute permission using the chmod command.
* Try running it as a regular user. What happens?
There is one interesting difference between the two scripts. In BASH you can control what number the script uses to indicate an error. In Python (with sys.exit anyway) you cannot. In Python you can exit indicating success by calling sys.exit() with nothing in the parentheses.
= Virtual Machine Backup Script =
== Overview ==
In Lab 2 Investigation 3 you performed a manual backup of all 3 virtual machines. While this is something both important and necessary, it's a tedious process. This is something you could automate through scripting. In this exercise you are going to write a script that will backup all three of your virtual machines. We will improve on this backup script in a later exercise. To begin, open your text editor (vi) on c7host and copy the following template in. Be sure to modify Author and Date with the correct information.

Navigation menu