This looks to me like an ideal opportunity to employ you some xargs
(or GNU Parallel):
getent passwd \
| awk -F: '$3>=1000 && $1!="nfsnobody" {print $1}' \
| xargs -I{} \
echo xfs_quota -x -c \"limit bsoft=5g bhard=6g {}\" /home
# output:
# xfs_quota -x -c "limit bsoft=5g bhard=6g userone" /home
# xfs_quota -x -c "limit bsoft=5g bhard=6g usertwo" /home
The advantage to using xargs
or parallel
is that you can simply remove the echo
when you're ready to run the command for real (possibly replacing it with sudo
, if necessary).
You can also use these utilities' -p
/ --interactive
(the latter is GNU-only) or --dry-run
(parallel
only) options, to get confirmation before running each one, or just to see what would run, before you run it.
The general method used above should work on most Unixes, and requires no GNU-specific xargs
options. The double quotes do need to be "escaped" so that they appear literally in the output. Note that the "replacement string," {}
, in xargs -I{}
can be anything you prefer, and -I
implies -L1
(run one command per input line rather than batching them up).
GNU Parallel does not require the -I
option ({}
is the default replacement string), and gives you the instant bonus of running many jobs in parallel, even if you don't want to bother learning about any of its other features.
As a side note, I'm not even sure if xfs_quota
's -c
option is supposed to be used like this, though I have no XFS filesystems handy to test. You may not have even have needed to deal with a quoted string in the first place (unless you expect usernames with whitespace in them, which I guess is possible), since it looks like you can give multiple -c
options on the same command line, according to the man page included with xfsprogs
4.5.something.
awk
– jesse_b Sep 13 '19 at 19:19awk
to print those single quotes literally, I cannot do that by simply using the escape character – jesse_b Sep 13 '19 at 19:21xargs
andparallel
exist to help you with exactly these kinds of problems. I've posted a solution below usingxargs
. – Kevin E Sep 14 '19 at 21:14