sergio_educacionit

python embebido info sistma

Jul 25th, 2026 (edited)
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 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,3,4,5
  14. #
  15. #)"
  16. last_upgrade="$(
  17. grep -B 1 'auto_upgrade' /var/log/apt/history.log \
  18. | tail -1 \
  19. | cut -d ' ' -f 2,3
  20. )"
  21.  
  22.  
  23.  
  24.  
  25.  
  26. # Se guarda la salida JSON de hostnamectl en una variable de Bash.
  27. datos_sistema="$(hostnamectl --json=short)"
  28.  
  29.  
  30. json_output=$(python3 - <<PYTHON
  31. import json
  32.  
  33. datos = {
  34. "fecha": "$fecha",
  35. "usuario": "$usuario",
  36. "host": "$host",
  37. "kernel": "$kernel",
  38. "ultima_actualizacion": "$last_upgrade",
  39. "sistema": json.loads(r'''$datos_sistema''')
  40. }
  41.  
  42. print(json.dumps(datos, indent=4, ensure_ascii=False))
  43. PYTHON
  44. )
  45.  
  46. # echo $json_output
Advertisement
Add Comment
Please, Sign In to add comment