User install package generates email

0

I wanted to know that is there any mechanism that when user install/uninstall any package by sudo. Its generates email and send it to the root's email address.
I am using centos 6.4 and usually install package through yum or by direct install(rpm).

Adnanh

Posted 2013-11-12T12:28:26.333

Reputation: 1

1

Related, but does not exactly answer your question: Mail me when someone runs sudo

– mpy – 2013-11-12T14:01:48.240

1sudo 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 uses apt-get install or rpm -i or pacman -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

Answers

0

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.

terdon

Posted 2013-11-12T12:28:26.333

Reputation: 45 216