Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Se usa sustitución de comandos para pasar valores a las variables.
- fecha="$(date "+%d-%m-%Y %H:%M")"
- usuario="$USER"
- host="$HOSTNAME"
- kernel="$(uname -a)"
- last_upgrade="$(
- grep -B 1 'Commandline: apt.*upgrade' /var/log/apt/history.log \
- | grep 'Start-Date' \
- | tail -1 \
- | cut -d ' ' -f 2
- )"
- # Se guarda la salida JSON de hostnamectl en una variable de Bash.
- datos_sistema="$(hostnamectl --json=short)"
- python3 - <<PYTHON
- import json
- # Bash expande las variables antes de enviar este código a Python.
- datos = {
- "fecha": "$fecha",
- "usuario": "$usuario",
- "host": "$host",
- "kernel": "$kernel",
- "ultima_actualizacion": "$last_upgrade",
- "sistema": json.loads(r'''$datos_sistema''')
- }
- # Se imprime el JSON de forma amigable.
- print(json.dumps(datos, indent=4, ensure_ascii=False))
- PYTHON
Advertisement
Add Comment
Please, Sign In to add comment