Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How would I automatically run a script after the apt-get actions dist-upgrade, install, remove and purge? Is there a suitable way of hooking into the APT lifecycle and run a custom script?

share|improve this question
Why don't you use aliases or include apt-get in a/your custom script ? – user55822 Oct 20 '12 at 8:21
Thanks for this question. I want to know how too – Suhaib Oct 20 '12 at 14:51
I'm looking for this answer too, except with apt-get update. @user55822, one reason would be because aliases only apply to your personal bash sessions. Therefore, anything besides you actually running apt-get update in a terminal (e.g. the update cron job, synaptic, etc.) won't make your script run. – strugee Mar 20 '13 at 4:33
up vote 5 down vote accepted

You can automatically run a script by creating a new file /etc/apt/apt.conf.d/99ownscript containing:

DPkg::Post-Invoke {"/bin/bash /path/to/"; };

Note that this file does not have to be executable, just 644 mode is sufficient.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.