简体   繁体   中英

Trying to read from file within existing for loop

Hello I am having a hard time figuring out how to complete the existing script I have written. In a nutsheel I am trying to set disk quotas based on an existing user for any user that doesn't have a quota set to 100MB or 102400 as below in the script. The logic seems to work currently but I have ran out of ideas for how to populate the $USER variable. Any help would be appreciated.

AWK=$(awk '{ print $4 }' test.txt)

USER=$(awk '{ print $1 }' test.txt)

for quota in $AWK;
do
    if [ "$quota" = 102400 ];
    then
        echo "Quota already set to 100MB for user: "$USER""
    else
        echo "Setting quota from template for user: $USER "
        edquota -p username "$USER"
    fi
done

The test.txt file is below:

user1   --  245 0   0
user2   --  245 102400  102400
user3   --  234 102400  102400
user4   --  234 1   0

Use a single loop that reads both variables from the file:

while read -r user a b quota c; do
    if [ "$quota" = 102400 ];
    then
        echo "Quota already set to 100MB for user: "$user""
    else
        echo "Setting quota from template for user: $user "
        edquota -p username "$user"
    fi
done < test.txt

The a , b , and c variables are just used to skip over those fields in the input file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM