[SOLVED] Set not-hard-coded quota during user creation
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The output after executing adduser titi.tutu is the following:
Code:
Setting quota for user `titi.tutu' to values of user `$(sort -t":" -k3 /etc/passwd | awk 'BEGIN{FS=":"} $3>=1000{print $1}' | head -1)' ...
edquota: user $(sort -t":" -k3 /etc/passwd | awk 'BEGIN{FS=":"} $3>=1000{print $1}' | head -1) does not exist.
adduser: `/usr/sbin/edquota -p $(sort -t":" -k3 /etc/passwd | awk 'BEGIN{FS=":"} $3>=1000{print $1}' | head -1) titi.tutu' returned error code 1. Exiting.
Upon consideration, I am not sure it can be done because my config file is not even executable...
So, if true, how would you achieve my goal please (retrieve the quota of first user having uid>=1000 and use it to set quota of the new user upon creation)?
Is it possible to insert shell commands inside text configuration files for variable initialization?
This could work if the config file in question were interpreted so that shell commands are executed. This is the case, for example, with the RHEL and SUSE network configuration files under /etc/sysconfig, but I would guess that the large majority of all config files are not interpreted.
Even if it is possible, it's probably not supported and not recommended for security reasons.
You'll want to look in the configuration file for adduser, /etc/adduser.conf and in there you will find a line for quotas. See "man adduser.conf"
Supposedly there is also an option for adduser to run a custom script, but I'm not finding it. However, QUOTAUSER in /etc/adduser.conf will likely get the quota assignment done.
You'll want to look in the configuration file for adduser, /etc/adduser.conf and in there you will find a line for quotas. See "man adduser.conf"
[...]However, QUOTAUSER in /etc/adduser.conf will likely get the quota assignment done.
If you recheck my OP, you'll notice that I've already used the QUOTAUSER variable inside /etc/adduser.conf
However, I don't want to assign it to a static value but to a dynamic one, hence this post...
Quote:
Originally Posted by Turbocapitalist
Supposedly there is also an option for adduser to run a custom script, but I'm not finding it.
This is probably what I'm looking for. Does it ring a bell to somebody please?
If you recheck my OP, you'll notice that I've already used the QUOTAUSER variable inside /etc/adduser.conf
Sorry, I should be more clear. It's an indirect reference. You can have your script set the quota for the template user from which the quota is copied and then, after that, call adduser with its QUOTAUSER reference.
Sorry, I should be more clear. It's an indirect reference. You can have your script set the quota for the template user from which the quota is copied and then, after that, call adduser with its QUOTAUSER reference.
You mean the following?
- set a quota for a "reference" user: edquota -u myReferenceUser
- specify in my /etc/adduser.conf: QUOTAUSER=myReferenceUser
If so, I've already done it. It works but it's not what I want because it's static/hard-coded and I might get into trouble should myReferenceUser be deleted some time later. That's why I would like to run a command to retrieve at least one curent user on the system.
Create an extra account which will exist only for the purpose of setting a quota. Then set /etc/adduser.conf: QUOTAUSER=myReferenceUser and leave it. Then in your script, set the quota for myReferenceUser just prior to calling adduser.
Though if there is a way to find the missing documentation about triggering a script from adduser that would be less convoluted.
Edit: from "man adduser"
Quote:
If the file /usr/local/sbin/adduser.local exists, it will be executed
after the user account has been set up in order to do any local setup.
The arguments passed to adduser.local are:
username uid gid home-directory
The environment variable VERBOSE is set according to the following
rule:
...
Last edited by Turbocapitalist; 07-17-2019 at 08:08 AM.
Though if there is a way to find the missing documentation about triggering a script from adduser that would be less convoluted.
Edit: from "man adduser":
If the file /usr/local/sbin/adduser.local exists, it will be executed
after the user account has been set up in order to do any local setup.
The arguments passed to adduser.local are:
username uid gid home-directory
The environment variable VERBOSE is set according to the following
rule:
...
Excellent, it did the job perfectly.
Thank you Turbocapitalist!
Post [SOLVED]
Quote:
Originally Posted by /usr/local/sbin/adduser.local
#!/bin/sh
username="$1"
uid="$2"
gid="$3"
home="$4"
referenceUserForQuota=$(sort -t":" -k3 /etc/passwd | awk 'BEGIN{FS=":"} $3>=1000{print $1}' | head -1)
echo -n "Setting same quota for new user '$username' than user '$referenceUserForQuota': ..."
edquota -p "$referenceUserForQuota" "$username" && echo "OK" || echo "KO!"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.