Skip to content

Instantly share code, notes, and snippets.

@Nama
Created November 7, 2019 14:06
Show Gist options
  • Save Nama/aec38952203c143ec8454b76b1ee48c7 to your computer and use it in GitHub Desktop.
Save Nama/aec38952203c143ec8454b76b1ee48c7 to your computer and use it in GitHub Desktop.
update and notify about updates
#!/usr/bin/python
from sh import hostname, checkupdates, yay, touch
from tg_bot import send
chatid = '000000000'
updates = checkupdates()
if updates:
touch('/tmp/system_upgrade.log')
msg = open('/tmp/system_upgrade.log', 'w')
touch('/tmp/system_upgrade_stdout.log')
stdout = open('/tmp/system_upgrade_stdout.log', 'w')
yay('-Syuq', '--noconfirm', '--noprogressbar', _out=stdout, _err=msg)
msg.close()
msg = open('/tmp/system_upgrade.log', 'r')
send(chatid, 'sendMessage', '*%s*_Upgrading these_\n```\n%s\n%s\n```%s' % (hostname(), updates, msg.read()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment