0

您好,我很难弄清楚如何完成我编写的现有脚本。简而言之,我正在尝试根据现有用户为任何没有将配额设置为 100MB 或102400在脚本中如下所示的用户设置磁盘配额。该逻辑目前似乎有效,但我已经没有关于如何填充$USER变量的想法。任何帮助,将不胜感激。

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

test.txt文件如下:

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

1 回答 1

2

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.

于 2015-06-25T00:02:14.183 回答