[sudo-users] Using shell variables in Command Alias Definitions

Ryan Chewning ryan at chewning.us
Tue Nov 17 07:33:01 MST 2015

Hi all,

I've spent several hours looking online for a way to use a shell variable
in a command alias. I'm using Debian 8 which ships with Sudo version
1.8.10p3 / Sudoers file grammar version 43.

I'm attempting to do something like this:

User_Alias PHPFPM_USERS = user1, user2, user3

Cmnd_Alias PHPFPMRESTART = /bin/systemctl restart php5-fpm@'$USER'.service
Cmnd_Alias PHPFPMSTART = /bin/systemctl start php5-fpm@$USER.service
Cmnd_Alias PHPFPMRELOAD = /bin/systemctl reload php5-fpm@$USER.service
Cmnd_Alias PHPFPMSTOP = /bin/systemctl stop php5-fpm@$USER.service
Cmnd_Alias PHPFPMSTATUS = /bin/systemctl status php5-fpm@$USER.service

I was hoping that $USER would be replaced at runtime with the user that's
executing the command to save the need to tens or hundreds of definitions.

Thanks for any help or guidance of a better way to do this!



More information about the sudo-users mailing list