Guys, I need some help, the output for my script below is causing me some issues....
Not sure where i am going wrong..
The out put should be all one line, but from some reasons its coming out on 4 lines...
Can you suggesst what i am doing wrong please!!!!!!
for MEDIA in `cat /tmp/freeze1 | awk '{print $2}'`
do
nbemmcmd -listmedia -mediaid $MEDIA | egrep "Media Type:|Last Mount:|Data Expiration:|Valid Images:" | awk '{print $3}' |
while read LINE
do
MEDIATYPE=`echo $LINE | cut -f1 -d" "`
LAST_MOUNT=`echo $LINE | cut -f2 -d" "`
DATE_EXPIRE=`echo $LINE | cut -f3 -d" "`
VALID_IMAGES=`echo $LINE | cut -f4 -d" "`
echo $MEDIA $MEDIATYPE $LAST_MOUNT $DATE_EXPIRE $VALID_IMAGES | awk '{printf " %-25s %-15s %-30s %-25s %-25s\n" , $1,$2,$3,$4,$5'} >> /tmp/FreezeMediaCheck.txt
done
done
Output of the script
==============BAA139 DLT DLT DLT DLT
BAA139 02/01/2001 02/01/2001 02/01/2001 02/01/2001
BAA139 INFINITY INFINITY INFINITY INFINITY
BAA139 35 35 35 35
BAA151 DLT DLT DLT DLT
BAA151 - - - -
BAA151 INFINITY INFINITY INFINITY INFINITY
BAA151 29 29 29 29King Regards
Junes
How many lines does this print out? for MEDIA in `cat /tmp/freeze1 | awk '{print $2}'` do echo $MEDIA doneIf it prints out more than one line, I don't see why you would expect everything to print out on one line.
Maybe if you take out the newline in awk's printf statement:
{printf " %-25s %-15s %-30s %-25s %-25s\n" , $1,$2,$3,$4,$5'}
to this:
{printf " %-25s %-15s %-30s %-25s %-25s" , $1,$2,$3,$4,$5'}
BTW, using the for loop like this is not only ugly but inefficient. Have you considered using a while loop and let it do the parsing:
while f1 MEDIA therest do . . done < /tmp/freeze1
Found a better way set -x
for MEDIA in `cat /tmp/freeze1 | awk '{print $2}'`
do
set -- `nbemmcmd -listmedia -mediaid $MEDIA | egrep "Media Type:|Last Mount:|Data Expiration:|Valid Images:" | awk '{print $3}'`
printf " %-25s %-15s %-30s %-25s %-25s\n" $MEDIA $1 $2 $3 $4 >>/tmp/FreezeMediaCheck.txt
doneKing Regards
Junes
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |