On Thu, 2002-10-24 at 21:34, Daniel Tan wrote:
> I have a file that i want to copy to each individual user's directory that
> is named as 1, 2, 3, ..... the filename is username.abook
> i need to write a script to some sort of automate the copying process into
> each directory and then find out the folder contains whose name and then
> overwriting the original file in it....
> 
> sounds confusing?
> 
> my scenario:
> i have a bunch of folders namely 1,2,3,4,5,6,7,8,9..................
> each folder actually contains a user's webmail settings.....username.abook,
> username.sig,username.pref
> i want to copy a file that can be used to overwrite all the *.abook in all
> the 1,2,3,4,5,6,7,8,9 directories...
> i need a script to automate the process....or a simple command for copying
> it without me having to find out directory 1 contains which user and
> directory 2 contains which user...
> 
Not enough information for my feable mind to see the solution.

Are you saying that for instance:
directory named 1 has a file in it named something like jdoe.abook

and you want to replace 1/jdoe.abook with the contents of a file named
new.abook

so if you were going to do this manually you would 
cp new.abook 1/jdoe.abook

if that is the case then someting like the script below should work
(untested)

#!/bin/sh
ctr=0
topdir="/set/this/to/the/directory/above/1 "
newbook="/path/to/new.abook"
for dir in $topdir/*; do
   userfile=$(ls $topdir/$dir/*.abook)
   if [ -n $userfile ]; then
      echo "copying $newbook to $topdir/$dir/$userfile
   
      #  uncomment the line below if the test run looks right   
      #cp $newbook $topdir/$dir/$userfile
      ctr=$(($ctr+1))
   else
      echo "there is no abook file in $topdir/$dir" 
   fi
done
echo "we copied $ctr files"
#end of script


This assumes that there is only one file named *.abook in each directory

Also assumes you want to change all *.abook files under $topdir

Let us know if this gets close.

Bret



-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@;redhat.com?subject=unsubscribe
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to