This is kinda hard to answer since you have not told us your distribution or which package manager you are using. There are various ways of doing this, one of which is making your package manager into a function. I will use apt-get
as an example.
Rename the apt-get
executable:
sudo mv /usr/bin/apt-get /usr/bin/apt-get.bin
Make a little wrapper script that calls apt-get
and then sends the email:
#!/bin/sh
./apt-get.bin "$@" && echo "User $SUDO_USER ran 'apt-get $@'" |
sendmail root@foo.com
Save the script above as /usr/bin/apt-get
and make it executable:
sudo chmod a+x /usr/bin/apt-get
Now, each time a user successfully runs apt-get
an email will be sent to root@foo.com
.
This is not the most elegant of ways and it can easily be bypassed by a user calling apt-get.bin
directly but it might serve for your needs. It will also not help if a user installs a package from source or uses aptitude
or dpkg
directly.
1
Related, but does not exactly answer your question: Mail me when someone runs sudo
– mpy – 2013-11-12T14:01:48.2401
sudo
does not install packages, it gives root access. What distribution are you using? I think what you are looking dor is an email when a user usesapt-get install
orrpm -i
orpacman -s
or whatever package management system you are using. – terdon – 2013-11-12T14:39:58.540@terdon yes you are right, can you help in that. – Adnanh – 2013-11-13T14:02:34.847