Update logged shell and allow non-interactive command execution
parent
80968b1970
commit
c9f902cd50
@ -1,2 +1,21 @@
|
||||
#!/bin/sh
|
||||
sudo /home/cvm/logshell
|
||||
#!/usr/bin/env python
|
||||
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)
|
Loading…
Reference in New Issue