![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Copy selected Directories | sigurarm | UNIX for Dummies Questions & Answers | 2 | 12-21-2007 12:57 PM |
| Copy single file to multiple directories | kthatch | UNIX for Dummies Questions & Answers | 2 | 11-11-2007 06:10 PM |
| copy multiple files in different directories | ken2834 | UNIX for Dummies Questions & Answers | 3 | 03-25-2007 01:35 PM |
| How do copy certain files and directories from one hard drive to another? | shorty | UNIX for Dummies Questions & Answers | 4 | 02-11-2006 08:26 PM |
| Copy Directories in to UNIX server | khan1978 | AIX | 3 | 12-09-2005 08:19 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Find directories not containing foo, and copy foo to them
Hello all,
I have a situation where I have a web root directory with a few thousand users spread out into 100 subdirectories in a 00/firstname.lastname, 01/firstname.lastname, etc. hierarchy. I suddenly need to make sure that each of these user directories contains a default index.html file (about 1/3 of them don't). I'm kind of a scripting newbie, so I'm having trouble with the mechanics. The thing that's most perplexing to me is to do a find in [00-99] -maxdepth=2 and search for all user directories that do not contain an index file (index.htm* and/or homepage.html). I think if I can figure out how to search on that string, I can figure out how to put the index file where it doesn't exist, so what I really need to know is how to search for what's missing. Thanks in advance for any help. Dave |
|
||||
|
Presumably there is a way to do it with "find" by NOTting a clause and I'm fairly sure someone will point it out soon.
Still, there is a way to do it with a shell script and since this part of the forum is about scripting you could try this: 1. It is easy to cycle through all your directories by doing an "ls -1" and feed that to a while-loop: Code:
ls -1 <yourstartdir> | while read dir ; do
print - "$dir"
done
Now, there is an option to "test", "-f", which is true, if a file with this name does exist. We could even exchange it to "-r", which is only true if a file exists and is available for read-access (i suppose you know that "test -r" and "[ -r ]" is the same, don't you?): Code:
ls -1 <yourstartdir> | while read dir ; do
if [ -r "$dir/index.html" ] ; then
print - "in dir $dir a readable index.html is missing"
fi
done
Hope this helps. bakunin |
|
||||
|
@pixelbeat: Ahem, but "-e" only tests the existence. It would be true even if "index.html" is not a file but a directory, symbolic link, FIFO, ...
True, the possibility of this happening is remote, but .... ;-)) bakunin |
|
||||
|
Thanks for the help. I got it sorted. Here's what I used:
Code:
#!/bin/sh
set -x
for i in `cat /data/dev/a-file-containing-a-listing-of-the-directories-i-want-to-work-in`
do
cd /data/dev/$i
for dir in `another-file-with-subdirectories-i-want-to-work-in`
do
echo $dir
if [ ! -f $dir/index.html -a ! -f $dir/index.htm -a ! -f $dir/homepage.htm ]; then
cp /data/dev/template.html $dir/index.html
fi
done
done
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|