Hi!
Following is the script to find the number of users and the total space consumed by them in the directory
But I am getting few errors Pls help me
data=`ls -lt $1 |tr -t [' '] ['\t']|tr -s '\t'|cut -f3,5`
count=0
flag=1
sum=0
users_flag=1
check=0
declare -a users
for a in $data
do
if [ $users_flag -eq 1 ]
then
for ((i = 0; $i <= count; $i++))
do
if [ $a = ${users[$count]} ]
then
flag=0
break
fi
done
if [ $flag -eq 1 ]
then
users[$count]=$a
count=expr`$count + 1`
echo $a >> userdata
fi
users_flag=0
else
if [ $flag -eq 1 ]
then
for b in $data
do
if [ $check -eq 0 ]
then
if [ $b = $a ]
then
check=1
fi
else
sum=`expr $sum + $b`
check=0
fi
done
fi
fi
done
Errors are
q3: 7: declare: not found
q3: 9: Syntax error: word unexpected (expecting "do")
Once you paste your script, highlight it and then click on the # on the icons bar above; this will keep the formatting. This makes it much easier to follow the code and the various conditions.
data=`ls -lt $1 |tr -t [' '] ['\t']|tr -s '\t'|cut -f3,5`
count=0
flag=1
sum=0
users_flag=1
check=0
declare -a users
for a in $data
do
if [ $users_flag -eq 1 ]
then
for ((i = 0; $i <= count; $i++))
do
if [ $a = ${users[$count]} ]
then
flag=0
break
fi
done
if [ $flag -eq 1 ]
then
users[$count]=$a
count=expr`$count + 1`
echo $a >> userdata
fi
users_flag=0
else
if [ $flag -eq 1 ]
then
for b in $data
do
if [ $check -eq 0 ]
then
if [ $b = $a ]
then
check=1
fi
else
sum=`expr $sum + $b`
check=0
fi
done
fi
fi
done
Which shell? Is this "sh", "ksh", "bash" or what?
echo $SHELL
Please show an example of what the output of the script should look like and state whether you count directory sizes as well as file sizes towards the per-user total.
Please state whether there are subdirectories in the directory you wish to analyse.