Update logged shell and allow non-interactive command execution

feature/node-rewrite
Sven Slootweg 12 years ago
parent 80968b1970
commit c9f902cd50

@ -1,2 +1,21 @@
#!/bin/sh #!/usr/bin/env python
sudo /home/cvm/logshell import sys, subprocess
try:
if sys.argv[1] == "-c":
try:
command = sys.argv[2]
interactive = False
except:
exit(1)
else:
interactive = True
except IndexError:
interactive = True
if interactive == True:
returncode = subprocess.call(["sudo", "/home/cvm/logshell"])
else:
returncode = subprocess.call(["sudo", "/home/cvm/logcmd", command])
exit(returncode)

@ -0,0 +1,35 @@
#!/usr/bin/env python
import random, string, subprocess, os, sys
from datetime import time, date, datetime
from time import strftime
try:
command = sys.argv[1]
except IndexError, e:
exit(1)
rand = ''.join(random.choice(string.letters + string.digits) for i in xrange(8))
rand = "%s_%s" % (strftime("%Y%m%d_%H%M%S"), rand)
logfile = open("/etc/cvm/log/log.%s" % rand, "w")
logfile.write("# NON-INTERACTIVE COMMAND EXECUTION\n")
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()
logfile.write(stdout + "\n" + stderr + "\n")
sys.stdout.write(stdout)
sys.stderr.write(stderr)
logfile.close()
exit(prc.returncode)

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/env python
# Depends on package: bsdutils # Depends on package: bsdutils
@ -8,14 +8,6 @@ from time import strftime
rand = ''.join(random.choice(string.letters + string.digits) for i in xrange(8)) rand = ''.join(random.choice(string.letters + string.digits) for i in xrange(8))
today = datetime.today()
day = today.day
month = today.month
year = today.year
hour = today.hour
minute = today.minute
second = today.second
rand = "%s_%s" % (strftime("%Y%m%d_%H%M%S"), rand) 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 2>/etc/cvm/log/log.%s.time -c 'su -s \"/bin/bash\" cvm' -a /etc/cvm/log/log.%s" % (rand, rand), shell=True)

Loading…
Cancel
Save