Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping and Incrementing with Bourne Shell 2

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
Thanks to this group I have the a fantastic backup script. I'd like to try to optimize it with your help.

I grep for the partitions to backup using the below:

grep "/usr1" /etc/vfstab
if [ $? -eq 0];
then <backup command> /usr1
fi

grep &quot;/usr2&quot; /etc/vfstab
if [ $? -eq 0];
then <backup command> /usr2
fi


In my environment the /usrX partitions are each an entire disk with user files or data. On some systems I may have up to 20.

How can I loop through the code and increment the &quot;X&quot; /usrX?

Thanks again for your advice all,

Michael42
 
First thoughts ( without too much !)
integer f1=1
while f1 < 21
do
ttx='/usr{$f1}'
grep $ttx /etc/vfstab
if [ $? -eq 0];
then <backup command> $ttx
fi
((f1=f1+1))
done



Dickie Bird (:)-)))
 
1. Get a list of all the usr directories in /
Code:
a=`ls -1d /usr*`

2. Iterate over that list
Code:
for i in $a;
do
  grep &quot;$i&quot;  /etc/vfstab
  if [ $? -eq 0];
    then <backup command> $i
  fi
done
 
Salem, dickiebird,

Your snippets are better than sliced bread. Please have a star on me.

Thanks for your help,

Michael42
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top