715
edits
Changes
→Virtual Machine Backup Script
# Exit successfully
</pre>
== Filling in the code ==
The below instructions provide all (or most) of the required code for filling in the above template. Fill in each section in sequence under the appropriate comment block.
=== Importing the required modules ===
For this script we will require the following modules:
* os
* system
* sys
Using the import statement (like we have done previously), import the above modules on one line.
<pre>
import os, system, sys
</pre>
=== Storing the output of the current user and checking to see if they are root. ===
We will use this to indicate an error if the script is not being run as root (without sudo). Create a variable called "whoami" and store the output of the whoami command in it. We will use the subprocess module, with the check_output function to accomplish this task.
<pre>
whoami = subprocess.check_output("whoami").decode("utf-8")
</pre>
=== Check the current user (who is executing the script) and store the information in the variable "currentuser". ===
We will use the os.geteuid() function for this task. Linux UID's (User IDs) start at 1000 for users. Root has a UID of 0.
<pre>
currentuser = os.geteuid()
</pre>