Skip to main content
Use 'getent passwd' instead of parsing /etc/passwd directly with Awk; reorder lower paragraphs in a more logical way
Source Link
Kevin E
  • 554
  • 5
  • 14

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 

ThisThe 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 patternmethod used above should work on most Unixes, and usesrequires no GNU-specific xargs options. The double quotes dodo 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.

The advantage to using xargs (or parallel) is that you can simply remove the echo—possibly replacing it with sudo, if necessary—when you're ready to run the command for real.

You can also use these utilities' -p / --interactive or --dry-run options (parallel only), to get confirmation before running each one, or just to see what would run, before you run it.

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.

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 

This general pattern should work on most Unixes, and uses 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.

The advantage to using xargs (or parallel) is that you can simply remove the echo—possibly replacing it with sudo, if necessary—when you're ready to run the command for real.

You can also use these utilities' -p / --interactive or --dry-run options (parallel only), to get confirmation before running each one, or just to see what would run, before you run it.

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.

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.

Use 'getent passwd' instead of parsing /etc/passwd directly with Awk
Source Link
Kevin E
  • 554
  • 5
  • 14

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}' /etc/passwd \ | 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 

This general pattern should work on most Unixes, and uses 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.

The advantage to using xargs (or parallel) is that you can simply remove the echo—possibly replacing it with sudo, if necessary—when you're ready to run the command for real.

You can also use these utilities' -p / --interactive or --dry-run options (parallel only), to get confirmation before running each one, or just to see what would run, before you run it.

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.

This looks to me like an ideal opportunity to employ you some xargs (or GNU Parallel):

awk -F: '$3>=1000 && $1!="nfsnobody" {print $1}' /etc/passwd \ | 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 

This general pattern should work on most Unixes, and uses 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.

The advantage to using xargs (or parallel) is that you can simply remove the echo—possibly replacing it with sudo, if necessary—when you're ready to run the command for real.

You can also use these utilities' -p / --interactive or --dry-run options (parallel only), to get confirmation before running each one, or just to see what would run, before you run it.

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.

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 

This general pattern should work on most Unixes, and uses 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.

The advantage to using xargs (or parallel) is that you can simply remove the echo—possibly replacing it with sudo, if necessary—when you're ready to run the command for real.

You can also use these utilities' -p / --interactive or --dry-run options (parallel only), to get confirmation before running each one, or just to see what would run, before you run it.

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.

Remove the part about macOS; XFS is not a Mac thing, so it can be inferred the OP is asking about Linux
Source Link
Kevin E
  • 554
  • 5
  • 14

This looks to me like an ideal opportunity to employ you some xargs (or GNU Parallel):

awk -F: '$3>=1000 && $1!="nfsnobody" {print $1}' /etc/passwd \ | 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 

This has been tested togeneral pattern should work on macOSmost Unixes, and Linuxuses 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.

The advantage to using xargs (or parallel) is that you can simply remove the echo—possibly replacing it with sudo, if necessary—when you're ready to run the command for real.

You can also use these utilities' -p / --interactive or --dry-run options (parallel only), to get confirmation before running each one, or just to see what would run, before you run it.

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.

This looks to me like an ideal opportunity to employ you some xargs (or GNU Parallel):

awk -F: '$3>=1000 && $1!="nfsnobody" {print $1}' /etc/passwd \ | 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 

This has been tested to work on macOS and Linux. The double quotes 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.

The advantage to using xargs (or parallel) is that you can simply remove the echo—possibly replacing it with sudo, if necessary—when you're ready to run the command for real.

You can also use these utilities' -p / --interactive or --dry-run options (parallel only), to get confirmation before running each one, or just to see what would run, before you run it.

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.

This looks to me like an ideal opportunity to employ you some xargs (or GNU Parallel):

awk -F: '$3>=1000 && $1!="nfsnobody" {print $1}' /etc/passwd \ | 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 

This general pattern should work on most Unixes, and uses 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.

The advantage to using xargs (or parallel) is that you can simply remove the echo—possibly replacing it with sudo, if necessary—when you're ready to run the command for real.

You can also use these utilities' -p / --interactive or --dry-run options (parallel only), to get confirmation before running each one, or just to see what would run, before you run it.

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.

Mention that GNU Parallel doesn't require the '-I' option; add links to Ole Tange's YouTube videos
Source Link
Kevin E
  • 554
  • 5
  • 14
Loading
Source Link
Kevin E
  • 554
  • 5
  • 14
Loading