私は、1000より大きいGIDと1000以下のGIDをフィルタリングするスクリプトを書いています。目的は、ローカルグループと非ローカルグループ(ADから来るグループ)をフィルタリングしてファイル..Bashスクリプト:Whileループとif文
グループ名とGIDを含むgroups.outというファイルがあります。それはどのような順序でもよい。以下は、ローカルグループ、非=ローカルグループ、およびGIDも含むサンプルファイルです。
1098052
1098051
domain users
fuse
gdm
haldaemon
とここで私はそれが成功を印刷しなければならないか、何らかのエラーが発生した場合、それが終了し、ファイルにエラーを追加する必要があり、ループの実行が成功した後
Read line by line from the file,
if the line is a number then check
if number greater than or equal to 1000 then check
if greater than or equal to 1000, append it to the file
else if number less than 1000 then dump it
else if erorr occurs append error to file and break the loop and exit
if the line is a string then check the gid of the string/group
if number greater than or equal to 1000 then append to file
else if gid less than 1000 then dump it
else if error occurs append error to file and break the loop and exit
want to repeat it in the loop line by line and if anywhere the error occurs loop should break and exit the entire script
を適用するロジックがあります。 以下は、多くの部分が欠けている私の調理されていないコードです。 gtまたはeqエラーには多くのエラーもあります。あなたはここで
fileA="groups.out"
value=1000
re='[a-z]'
num='[0-9]'
while IFS= read lineA
do
group=$(getent group "$lineA" | awk -F: '{print $3}')
# ------Don't know how to check if a number or string -----
if [ "$group" -gt "$value" ]; then
echo "$lineA" >> ldapgroups.out 2>> error.out
elif [ "$group" -lt "$value" ]; then
echo "$lineA" >> /dev/null 2>> error.out
else
echo " FAILED"
exit 1
fi
ここでは、bashの数値または文字列をチェックする方法を示します。http://stackoverflow.com/a/806923/524743 – Samuel