Fix interactive mode for logshell

feature/node-rewrite
Sven Slootweg 12 years ago
parent c9f902cd50
commit 95a3927e0a

@ -1,11 +1,15 @@
#!/usr/bin/env python
import sys, subprocess
import sys, subprocess, time
try:
if sys.argv[1] == "-c":
try:
command = sys.argv[2]
interactive = False
if command == 'su -s "/bin/bash" cvm':
interactive = True
else:
interactive = False
except:
exit(1)
else:
@ -15,6 +19,7 @@ except IndexError:
if interactive == True:
returncode = subprocess.call(["sudo", "/home/cvm/logshell"])
else:
returncode = subprocess.call(["sudo", "/home/cvm/logcmd", command])

@ -18,14 +18,20 @@ logfile.write("$ " + command + "\n")
prc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while prc.poll():
stdout, stderr = prc.communicate()
logfile.write(stdout + "\n" + stderr + "\n")
sys.stdout.write(stdout)
sys.stderr.write(stderr)
stdout, stderr = prc.communicate()
while prc.poll() is None:
stdout = prc.stdout.read()
stderr = prc.stderr.read()
if stdout.strip() != "":
sys.stdout.write(stdout)
logfile.write(stdout + "\n")
if stderr.strip() != "":
sys.stderr.write(stderr)
logfile.write(stderr + "\n")
stdout = prc.stdout.read()
stderr = prc.stderr.read()
logfile.write(stdout + "\n" + stderr + "\n")
sys.stdout.write(stdout)

@ -10,7 +10,7 @@ rand = ''.join(random.choice(string.letters + string.digits) for i in xrange(8))
rand = "%s_%s" % (strftime("%Y%m%d_%H%M%S"), rand)
subprocess.call("script -qt 2>/etc/cvm/log/log.%s.time -c 'su -s \"/bin/bash\" cvm' -a /etc/cvm/log/log.%s" % (rand, rand), shell=True)
subprocess.call("script -qt -c 'su -s \"/bin/bash\" cvm' -a /etc/cvm/log/log.%s 2>/etc/cvm/log/log.%s.time" % (rand, rand), shell=True)
if os.environ['SHELL'] != "/bin/bash":
os.remove("/etc/cvm/log/log.%s.time" % rand)

Loading…
Cancel
Save