The original data from which I've created these 3 files
quota username bytes
20480000 [email protected] 896
30720000 [email protected] 3002766
20480000 [email protected] 20472940
20480000 [email protected] 2351
Here I want that if bytes if any user is equal or greater than to quota then the username should be printed or I'll perform another task to block the user.
I have 3 files such as these:
users.txt
Output:
[email protected]
[email protected]
consumed_quota.txt
Output:
20
5
allowed_quota.txt
Output:
20
10
I want that if user [email protected] from file users.txt consumed_quota is equal to or greater than allowed_quota then print the user.
What would be the bash program?
Kindly help out.
I'm trying below code, but it is printing all users in stead of the matching one.
#!/bin/bash
mysql -e 'select postfix.m.quota, q.* from postfix.mailbox m, postfix.quota2 q where m.username = q.username' > /tmp/all_users_query
username=`cat /tmp/all_users_query | cut -f2 | grep -v username > /tmp/usernf`
quota=`cat /tmp/all_users_query | cut -f1 | grep -v quota > /tmp/quotaf`
consumed=`cat /tmp/all_users_query | cut -f3 | grep -v bytes > /tmp/consumedf`
function show_users()
{
username=`cat /tmp/usernf`
for i in $username
do
echo $i
done
}
function actual_quota()
{
quota=`cat /tmp/quotaf`
for i in $quota
do
akb=`echo $i/1000 | bc`
amb=`echo $akb/1000 | bc`
echo $amb
done
}
function used_quota()
{
consumed=`cat /tmp/consumedf`
for i in $consumed
do
ukb=`echo "$i/1000" | bc`
umb=`echo "$ukb/1000" | bc`
echo "$umb"
done
}
declare -a arr_users="$(show_users)"
declare -a arr_act_quota="$(actual_quota)"
declare -a arr_use_quota="$(used_quota)"
for u in ${arr_users[@]}
do
for i in ${arr_use_quota[@]}
do
# echo $i;
for j in ${arr_act_quota[@]}
do
if [ "$j" == "$i" ]
then
echo $u;
break;
fi
done
done
done
Output:?