Created
October 24, 2013 15:00
-
-
Save SeqviriouM/7138790 to your computer and use it in GitHub Desktop.
Homework_2_Runlevel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re,tarfile | |
runlevel = re.compile("env DEFAULT_RUNLEVEL=\d*$") | |
initdefault = re.compile(".*:initdefault:.*$") | |
# Open archive | |
tar_archive = tarfile.open("etc.tar.gz", "r:gz") | |
# Extract necessary file | |
file = tar_archive.extractfile("etc/init/rc-sysinit.conf") | |
# Try to open file inittab | |
try: | |
init_file = tar_archive.extractfile('etc/inittab') | |
init = True | |
except Exception: | |
init = False | |
# Variable to safe runlevel | |
level = 0 | |
if (init): | |
# If file inittab exists | |
for line in init_file: | |
if initdefault.search(line) != None: | |
level = line[3] | |
else: | |
# Search in file rc-sysinit.conf | |
for line in file: | |
if runlevel.search(line) != None: | |
level = line[len(line)-2] | |
# Print result | |
print str(level) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment