I'm trying to return from a chrooted environment. 'sys.exit()' does exit but also seams to exit the program. (I just started looking into Python just a few days ago but I can't find anything close to what I want to do googling the web.) Any way to exit the chrooted environment and remain in the program to execute more commands?
The effect I need is this:
[root@lhs python]# ls python.py [root@lhs python]# chroot /home/devyn bash-3.00# ls bin dev etc home lib pass-devyn.txt root devyn-dir usr var bash-3.00# exit exit [root@lhs python]# ls python.py [root@lhs python]#
Thanks, Dev
# chroot # except OSError, (errno, msg):
import os import sys
root="/home/devyn/"
try: if os.path.exists(root): print "[0]The path '%s' exists. Going to 'chroot' to it... :)" % (root) print "[0-0]FILES: %s " % (os.listdir('/')) os.chroot (root) else: print "[0]Looks like we are already chrooted to '%s'. :P" % (root) print "[0]CWD: %s" % (os.getcwd()) print "[0-1]FILES: %s " % (os.listdir('/')) except Exception, e: print "[0]Could not chroot" print "[0]Problem: %s" %(e)
try: if os.path.exists(root): try: os.chroot (root) except Exception, e: print "[1][WARNING] oOps! Problem in 'execWithRedirect' %s : %s : %s : %s : [EXCEPTION]%s" %(command, argv, root, newPgrp, e) pass else: print "[1]Looks like we are already chrooted to '%s'. :P" % (root)