Quote:
|
If I need to be referred to somewhere else to ask a Linux Question, please tell me where to go.
|
No, you are in the right place. It is just that the way you phrased the question it looked like it came from a book or a teacher
and hence part of the LQ rules are that homework is not to be done in this way.
So firstly, you may have missed it but please place code in [code][/code] tags so we can see what is going on better and the indentation will not be lost.
Second, Telengard did provide valuable information regarding your for loop. Effectively the loop only passes values to your variable based on the information delivered.
In your example you present only a single item:
Code:
for record in homedir.temp
Here you have presented the string 'homedir.temp' and seeing that you never use the variable record within the loop itself, everything in the loop is performed once.
That being said, maybe you would like to identify more of what it is you want to do rather than how you are trying to do it?
Let me step through your code and make some observations:
Code:
awk -F":" '{print $6}' /etc/passwd > passwdhome.temp
LIST=$(grep -i "home" passwdhome.temp)
echo "$LIST" > homedir.temp
So the use of awk and grep here is not really required seeing as awk has both skills already.
Code:
FINDGRAND=$(du -s /home)
echo "${FINDGRAND}" > gtotal.temp
I left this until here but it also goes for the first piece of code as well, as you do not use the variable anywhere else you do not need to assign
it and then echo the variable. Just simply echo what you have between $() and redirect to the file:
Code:
echo "$(du -s /home)" > gtotal.temp
Code:
for record in homedir.temp
do
So this was my point above in that record is never used below and you are passing the string and not the contents of homedir.temp (How would you normally display the contents
of a file at the command prompt??)
Code:
DIR=$(awk -F" " '{print $1} homedir.temp)
I think you need to understand what is the contents of homedir.temp? Based on earlier code it is not space separated information.
Code:
SIZE=$(du -s $DIR)
echo "${SIZE}" > size.temp
GTOTAL=$(awk -F" " '{print $1}' gtotal.temp)
PER1=$(echo "scale=2; $SIZE/$GTOTAL" | bc)
PER2=$(echo "scale=0; $PER1*100" | bc)
echo -e "${DIR}\t${TOTAL}\t${PER2}" >> diskhogs1.file
done
My question to you here would be, why use bc when you are using awk everywhere else and it can do decimal calculations??
I hope you find some of this useful. I would add that you could do it all as an awk script if you really wanted to
