[sudo-users] Running a command every time sudo is used

Ahmed Badr badara at gmail.com
Thu Nov 3 13:40:38 MDT 2016


Hi

Greetings from a newbie :). I wonder if you could help me setting
things up on a new server I'm currently configuring.

Ubuntu Server 16.04
sudo version: 1.8.16

I would like to run a specific command as root every time a user uses
sudo. This specific command need to run before the command passed to
sudo. How can this be achieved?

Reading the man pages (I still don't fully understand sudo eco system)
I think this is possible using the sudoer file (or rather sudoer.d
drectory on Deb/Ubuntu). However I don't know how to do it with EBNF.

The reason I want to do this:
I formated the root partition with Btrfs and I would like to take a
snapshot (using snapper) before every root change imitating OpenSUSE
behavior. The command I'll be using is:

    sudo snapper create -d "Description"

and I would like the description to hold the username and the command
the user passed to sudo. For example:

    sudo snapper create -d "jim: sudo apt install mc"

I appreciate your help.
-- 
A.B.


More information about the sudo-users mailing list