I'm doing a script with python3 in linux to let me know when someone is connected to my system and allows me to throw the user I want. I have this script and it works with graphical interface with the tkinter library. The problem is that when I'm going to enter the user's tty in the four-letter variable and give it to send, the code of the delete function does not work (sudo pkill -9 -t nombreusuario)
.
Also e tested with: subprocess.run("sudo pkill -9 -t {0}").format(nombreusuario)
1.I would like to know how to enter a python variable in a linux command so that in this case it can throw the user.
2.I also want to know if the way to save the result of an Entry that I do is fine. For example:
cuadrotexto=Entry()
resultadoEntry=cuadrotexto.get()
Would that be like saving what I put in the text box in the resultEntry variable?
#! /usr/bin/python3
#-*- coding: utf-8 -*-
from tkinter import *
import subprocess
from tkinter import messagebox
a=subprocess.check_output("who|wc -l",shell=True)
b=int(a.decode("utf-8").strip())
lista=subprocess.check_output("who",shell=True)
lista2=subprocess.check_output('who| cut -d " " -f 1,4,6',shell=True)
def funelim():
def elimiusr():
subprocess.run("sudo pkill -9 -t nombreusuario")
raiz=Tk()
raiz.title("Eliminar usuario")
raiz.resizable(0,0)
raiz.geometry("380x150")
texto=Label(raiz,text="Elige el tty del usuario que quieres eliminar")
texto.grid(row=0,column=0,sticky="w")
texto2=Label(raiz,text=lista2)
texto2.grid(row=1,column=0,sticky="w",pady=10)
cuadronombre=Entry(raiz)
cuadronombre.grid(row=2,column=0,sticky="w")
cuadronombre.config(justify="center")
nombreusuario=cuadronombre.get()
boton3=Button(raiz,text="Enviar",command=elimiusr)
boton3.grid(row=2,column=0,sticky="e",padx=170)
raiz.mainloop()
def elimus():
if b>1:
def exit():
root.destroy()
root=Tk()
root.title("Alguien se a conectado al sistema")
root.resizable(0,0)
root.geometry("380x150")
miLabel=Label(root,text="Alguien se a conectado al sistema, ¿Que quiere hacer?")
miLabel.grid(row=0,column=0)
miLabel2=Label(root,text=lista).grid(column=0,row=1,pady=10,sticky="w")
boton1=Button(text="Elim.Usuario",command=funelim)
boton1.grid(column=0,row=2,sticky="w")
boton2=Button(text="Salir",command=exit)
boton2.grid(column=0,row=2,sticky="e")
root.mainloop()
elimus()