LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 07-17-2019, 03:51 AM   #1
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
Question Set not-hard-coded quota during user creation


Is it possible to insert shell commands inside text configuration files for variable initialization?

Indeed, I'm wondering because the example below doesn't work (my custom command is taken as plain text):

Quote:
Originally Posted by /etc/adduser.conf
QUOTAUSER=$(sort -t":" -k3 /etc/passwd | awk 'BEGIN{FS=":"} $3>=1000{print $1}' | head -1)
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)?

Thank you

Last edited by l0f4r0; 07-18-2019 at 04:52 AM.
 
Old 07-17-2019, 04:01 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by l0f4r0 View Post
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.
 
Old 07-17-2019, 04:03 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,326
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
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.
 
Old 07-17-2019, 04:15 AM   #4
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Original Poster
Rep: Reputation: 290Reputation: 290Reputation: 290
Quote:
Originally Posted by Turbocapitalist View Post
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 View Post
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?
 
Old 07-17-2019, 04:23 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,326
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Quote:
Originally Posted by l0f4r0 View Post
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.
 
Old 07-17-2019, 07:27 AM   #6
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Original Poster
Rep: Reputation: 290Reputation: 290Reputation: 290
Quote:
Originally Posted by Turbocapitalist View Post
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.
 
Old 07-17-2019, 08:06 AM   #7
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,326
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
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.
 
1 members found this post helpful.
Old 07-18-2019, 04:48 AM   #8
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Original Poster
Rep: Reputation: 290Reputation: 290Reputation: 290
Quote:
Originally Posted by Turbocapitalist View Post
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!"
 
  


Reply

Tags
/etc, quota, shell, user



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
commands inside shell script thunderstorm1! Linux - Newbie 2 02-19-2014 07:14 AM
Shell script inside shell script treotan Linux - General 4 02-19-2009 06:34 AM
where to place certiain commands inside shell script beeblequix Linux - Newbie 8 08-10-2006 11:12 AM
well, there's info written inside /etc/group. accidentally del /etc/group in RedHat9 karmakid Red Hat 1 07-27-2005 10:27 PM
/etc/hosts, /etc/resolve.conf and /etc/host.conf config probs below_average Linux - Networking 1 12-08-2004 10:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration