Running Apt Updates with Python

Saving the file below as a .py file and then run using Python3. It will run the following:

  • sudo apt update
  • sudo apt upgrade -y
  • sudo apt full-upgrade -y
  • sudo apt dist-upgrade -y
  • sudo apt autoremove -y
  • sudo apt clean -y
  • sudo apt purge -y
import subprocess

Run 'sudo apt update'

subprocess.run(['sudo', 'apt', 'update'])

Run 'sudo apt upgrade -y'

subprocess.run(['sudo', 'apt', 'upgrade', '-y'])

Run 'sudo apt full-upgrade -y'

subprocess.run(['sudo', 'apt', 'full-upgrade', '-y'])

Run 'sudo apt dist-upgrade -y'

subprocess.run(['sudo', 'apt', 'dist-upgrade', '-y'])

Run 'sudo apt autoremove -y'

subprocess.run(['sudo', 'apt', 'autoremove', '-y'])

Run 'sudo apt clean -y'

subprocess.run(['sudo', 'apt', 'clean', '-y'])

Run 'sudo apt purge -y'

subprocess.run(['sudo', 'apt', 'purge', '-y'])