sergio_educacionit

python embebido info sistma

Jul 25th, 2026
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Se usa sustitución de comandos para pasar valores a las variables.
  4. fecha="$(date "+%d-%m-%Y %H:%M")"
  5. usuario="$USER"
  6. host="$HOSTNAME"
  7. kernel="$(uname -a)"
  8.  
  9. last_upgrade="$(
  10. grep -B 1 'Commandline: apt.*upgrade' /var/log/apt/history.log \
  11. | grep 'Start-Date' \
  12. | tail -1 \
  13. | cut -d ' ' -f 2
  14. )"
  15.  
  16. # Se guarda la salida JSON de hostnamectl en una variable de Bash.
  17. datos_sistema="$(hostnamectl --json=short)"
  18.  
  19. python3 - <<PYTHON
  20. import json
  21.  
  22. # Bash expande las variables antes de enviar este código a Python.
  23. datos = {
  24. "fecha": "$fecha",
  25. "usuario": "$usuario",
  26. "host": "$host",
  27. "kernel": "$kernel",
  28. "ultima_actualizacion": "$last_upgrade",
  29. "sistema": json.loads(r'''$datos_sistema''')
  30. }
  31.  
  32. # Se imprime el JSON de forma amigable.
  33. print(json.dumps(datos, indent=4, ensure_ascii=False))
  34. PYTHON
  35.  
Advertisement
Add Comment
Please, Sign In to add comment