I am trying to read user and server details from file tempo.txt
and then check the disk space usage of the file system on that unix account using another script server_disk_space.sh
.But I am not able to figure out why while loop is only working for first line and for loop is working fine.Please help me understand this.
Using while loop
#!/usr/bin/ksh
while read line
do
r1=`echo $line | cut -d"#" -f1`;
r2=`echo $line | cut -d"#" -f2`;
apx_server_disk_space.sh $r2 $r1
done<tempo.txt
Output
8
Using for loop
#!/usr/bin/ksh
for line in $(cat tempo.txt)
do
r1=`echo $line | cut -d"#" -f1`;
r2=`echo $line | cut -d"#" -f2`;
apx_server_disk_space.sh $r2 $r1
done
Output
8
23
54
89
12
Contents of server_disk_space.sh
#!/usr/bin/ksh
user=$1
server=$2
count=`ssh ${user}@${server} "df -h ."`
echo ${count} | awk '{print $12}' | tr -d %
Above script outputs the value of Use percentage
of Disk Usage on any server .
Contents of tempo.txt
abclin542#abcwrk47#
abclin540#abcwrk1#
abclin541#abcwrk2#
abclin543#abcwrk3#
abclin544#abcwrk33#
while IFS= read
used so often, instead ofIFS=; while read..
? – Gilles 'SO- stop being evil' Nov 27 '12 at 22:37