Skip to main content
explain efficiency
Source Link
user1404316
  • 3.1k
  • 15
  • 23

You seem on the ball so I won't spoon-feed you a script, but here are some pointers:

  1. You're using awk incorrectly. Try this instead:

     awk -F: -v uid_min=${UID_MIN:-1000} '$3%2==0 && $3>uid_min && $3!=65534{print $6}' /etc/passwd
    
  2. There's no need for cat.

  3. Use your awk output as the input to your read loop, ie. while read USER_HOME_DIR ; do ... ; done < $(awk...). Understand that this will mean that only one awk process needs to be spawned, while your original script spawns a separate awk process for each line, so this is much more efficient.

  4. Add a check in your awk program to limit it to UID's above 1000, or you will inadvertently perform your copy for many system users.

  5. Note that in #1 above, I changed your $1 to $6 in order to pull the user's home directory instead of the user's name.

  6. I just noticed on my debian machine that there exists a 'nobody' user with UID 65534, so you may need to account for that. I modified the awk statement in #1 accordingly.

  7. As per user Jeff Schaller's comment, I've modified the awk program to account for a custom minimum UID. The form ${UID_MIN:-1000} means set the value as 1000 if it would otherwise be null or unset.

You seem on the ball so I won't spoon-feed you a script, but here are some pointers:

  1. You're using awk incorrectly. Try this instead:

     awk -F: -v uid_min=${UID_MIN:-1000} '$3%2==0 && $3>uid_min && $3!=65534{print $6}' /etc/passwd
    
  2. There's no need for cat.

  3. Use your awk output as the input to your read loop, ie. while read USER_HOME_DIR ; do ... ; done < $(awk...).

  4. Add a check in your awk program to limit it to UID's above 1000, or you will inadvertently perform your copy for many system users.

  5. Note that in #1 above, I changed your $1 to $6 in order to pull the user's home directory instead of the user's name.

  6. I just noticed on my debian machine that there exists a 'nobody' user with UID 65534, so you may need to account for that. I modified the awk statement in #1 accordingly.

  7. As per user Jeff Schaller's comment, I've modified the awk program to account for a custom minimum UID. The form ${UID_MIN:-1000} means set the value as 1000 if it would otherwise be null or unset.

You seem on the ball so I won't spoon-feed you a script, but here are some pointers:

  1. You're using awk incorrectly. Try this instead:

     awk -F: -v uid_min=${UID_MIN:-1000} '$3%2==0 && $3>uid_min && $3!=65534{print $6}' /etc/passwd
    
  2. There's no need for cat.

  3. Use your awk output as the input to your read loop, ie. while read USER_HOME_DIR ; do ... ; done < $(awk...). Understand that this will mean that only one awk process needs to be spawned, while your original script spawns a separate awk process for each line, so this is much more efficient.

  4. Add a check in your awk program to limit it to UID's above 1000, or you will inadvertently perform your copy for many system users.

  5. Note that in #1 above, I changed your $1 to $6 in order to pull the user's home directory instead of the user's name.

  6. I just noticed on my debian machine that there exists a 'nobody' user with UID 65534, so you may need to account for that. I modified the awk statement in #1 accordingly.

  7. As per user Jeff Schaller's comment, I've modified the awk program to account for a custom minimum UID. The form ${UID_MIN:-1000} means set the value as 1000 if it would otherwise be null or unset.

remove mention other answer
Source Link
user1404316
  • 3.1k
  • 15
  • 23

You seem on the ball so I won't spoon-feed you a script, but here are some pointers:

  1. You're using awk incorrectly. Try this instead:

     awk -F: -v uid_min=${UID_MIN:-1000} '$3%2==0 && $3>uid_min && $3!=65534{print $6}' /etc/passwd
    
  2. There's no need for cat.

  3. Use your awk output as the input to your read loop, ie. while read USER_HOME_DIR ; do ... ; done < $(awk...).

  4. Add a check in your awk program to limit it to UID's above 1000, or you will inadvertently perform your copy for many system users.

  5. Note that in #1 above, I changed your $1 to $6 in order to pull the user's home directory instead of the user's name.

  6. I just noticed on my debian machine that there exists a 'nobody' user with UID 65534, so you may need to account for that. I modified the awk statement in #1 accordingly.

  7. As per user Jeff Schaller's comment, I've modified the awk program to account for a custom minimum UID. The form ${UID_MIN:-1000} means set the value as 1000 if it would otherwise be null or unset.

You seem on the ball so I won't spoon-feed you a script, but here are some pointers:

  1. You're using awk incorrectly. Try this instead:

     awk -F: -v uid_min=${UID_MIN:-1000} '$3%2==0 && $3>uid_min && $3!=65534{print $6}' /etc/passwd
    
  2. There's no need for cat.

  3. Use your awk output as the input to your read loop, ie. while read USER_HOME_DIR ; do ... ; done < $(awk...).

  4. Add a check in your awk program to limit it to UID's above 1000, or you will inadvertently perform your copy for many system users.

  5. Note that in #1 above, I changed your $1 to $6 in order to pull the user's home directory instead of the user's name.

  6. I just noticed on my debian machine that there exists a 'nobody' user with UID 65534, so you may need to account for that. I modified the awk statement in #1 accordingly.

  7. As per user Jeff Schaller's comment, I've modified the awk program to account for a custom minimum UID. The form ${UID_MIN:-1000} means set the value as 1000 if it would otherwise be null or unset.

You seem on the ball so I won't spoon-feed you a script, but here are some pointers:

  1. You're using awk incorrectly. Try this instead:

     awk -F: -v uid_min=${UID_MIN:-1000} '$3%2==0 && $3>uid_min && $3!=65534{print $6}' /etc/passwd
    
  2. There's no need for cat.

  3. Use your awk output as the input to your read loop, ie. while read USER_HOME_DIR ; do ... ; done < $(awk...).

  4. Add a check in your awk program to limit it to UID's above 1000, or you will inadvertently perform your copy for many system users.

  5. Note that in #1 above, I changed your $1 to $6 in order to pull the user's home directory instead of the user's name.

  6. I just noticed on my debian machine that there exists a 'nobody' user with UID 65534, so you may need to account for that. I modified the awk statement in #1 accordingly.

  7. As per user Jeff Schaller's comment, I've modified the awk program to account for a custom minimum UID. The form ${UID_MIN:-1000} means set the value as 1000 if it would otherwise be null or unset.

use uid_min
Source Link
user1404316
  • 3.1k
  • 15
  • 23

You seem on the ball so I won't spoon-feed you a script, but here are some pointers:

  1. You're using awk incorrectly. Try this instead:

     awk -F: -v uid_min=${UID_MIN:-1000} '$3%2==0 && $3>1000$3>uid_min && $3!=65534{print $6}' /etc/passwd
    
  2. There's no need for cat.

  3. Use your awk output as the input to your read loop, ie. while read USER_HOME_DIR ; do ... ; done < $(awk...).

  4. Add a check in your awk program to limit it to UID's above 1000, or you will inadvertently perform your copy for many system users.

  5. Note that in #1 above, I changed your $1 to $6 in order to pull the user's home directory instead of the user's name.

  6. I just noticed on my debian machine that there exists a 'nobody' user with UID 65534, so you may need to account for that. I modified the awk statement in #1 accordingly.

  7. As per user Jeff Schaller's comment, I've modified the awk program to account for a custom minimum UID. The form ${UID_MIN:-1000} means set the value as 1000 if it would otherwise be null or unset.

You seem on the ball so I won't spoon-feed you a script, but here are some pointers:

  1. You're using awk incorrectly. Try this instead:

     awk -F: '$3%2==0 && $3>1000 && $3!=65534{print $6}' /etc/passwd
    
  2. There's no need for cat.

  3. Use your awk output as the input to your read loop, ie. while read USER_HOME_DIR ; do ... ; done < $(awk...).

  4. Add a check in your awk program to limit it to UID's above 1000, or you will inadvertently perform your copy for many system users.

  5. Note that in #1 above, I changed your $1 to $6 in order to pull the user's home directory instead of the user's name.

  6. I just noticed on my debian machine that there exists a 'nobody' user with UID 65534, so you may need to account for that. I modified the awk statement in #1 accordingly.

You seem on the ball so I won't spoon-feed you a script, but here are some pointers:

  1. You're using awk incorrectly. Try this instead:

     awk -F: -v uid_min=${UID_MIN:-1000} '$3%2==0 && $3>uid_min && $3!=65534{print $6}' /etc/passwd
    
  2. There's no need for cat.

  3. Use your awk output as the input to your read loop, ie. while read USER_HOME_DIR ; do ... ; done < $(awk...).

  4. Add a check in your awk program to limit it to UID's above 1000, or you will inadvertently perform your copy for many system users.

  5. Note that in #1 above, I changed your $1 to $6 in order to pull the user's home directory instead of the user's name.

  6. I just noticed on my debian machine that there exists a 'nobody' user with UID 65534, so you may need to account for that. I modified the awk statement in #1 accordingly.

  7. As per user Jeff Schaller's comment, I've modified the awk program to account for a custom minimum UID. The form ${UID_MIN:-1000} means set the value as 1000 if it would otherwise be null or unset.

account for nobody
Source Link
user1404316
  • 3.1k
  • 15
  • 23
Loading
in lists, it takes twice as much indenting for formatting
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264
Loading
Source Link
user1404316
  • 3.1k
  • 15
  • 23
Loading