![]() |
|
|
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 |
| for loop problem | mdap | Shell Programming and Scripting | 3 | 08-16-2008 02:27 PM |
| Loop Problem | namishtiwari | UNIX for Dummies Questions & Answers | 4 | 07-15-2008 12:01 PM |
| awk and loop problem | invinzin21 | Shell Programming and Scripting | 3 | 02-04-2008 09:54 PM |
| loop Problem | dhananjaysk | Shell Programming and Scripting | 3 | 03-31-2006 02:05 PM |
| problem with while loop | mridula | High Level Programming | 1 | 12-11-2005 11:44 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi ALL
I am greping some thing from a file,some thing is "/var/www/html" /var/www"/example" and so on its showing like this when u use echo.i want to pass each one of them in a loop for processing.Like start with /var/www/html then 2nd and so one But that not working any iead how i give one by one value. My code docroot=$(grep -H DocumentRoot /etc/httpd/conf.d/*.conf | awk -F' ' '{ print $3 }'| sort -u | uniq) doccount=$(grep -H DocumentRoot /etc/httpd/conf.d/*.conf | awk -F' ' '{ print $3 }'| sort -u | uniq | wc -l) for (( i=0; i <= $doccount; ++i )) do confd="$docroot\n" echo $confd find $confd -type d -perm /o=w | while read DIR do do some thing done ## while done done ##for done |
|
||||
|
Thanks for reply,Not working means when i pass one value in loop to Variable $confd,I don't process it instead it consider online with all the document root.I show you my code,and if i run staticelly using /var/www/html output is fine but when i put in loop problem occourced.I show you output for both. Code:
#!/bin/bash
let test=0
abc="/var/www/html"
docroot=$(grep -H DocumentRoot /etc/httpd/conf.d/*.conf | awk -F' ' '{ print $3 }'| sort -u | uniq)
doccount=$(grep -H DocumentRoot /etc/httpd/conf.d/*.conf | awk -F' ' '{ print $3 }'| sort -u | uniq | wc -l)
#i=0
#while [ $i -le $doccount ]
# do
# confd="$docroot\n"
#echo $confd
find $abc -type d -perm /o=w | while read DIR
do
test=$(cd "$DIR"; ls -A *.html *.php 2>/dev/null | wc -l)
if [ "$test" != "0" ]
then
echo "DIR Found WITH FILES"$DIR $test
fi
if [ `ls -a "$DIR" | wc -l` -le 2 ]
then
echo "Writable_dir Empty"$DIR
fi
done
#i=$(( $i + 1 ))
#done
count=$(find /var/www/html/ -type f -perm /o=w | grep -i ".htaccess"| wc -l )
find "$abc" -type f -perm /o=w | grep -i ".htaccess" | awk -F. '{ print $1 }' | while read this
do
echo "_htaccess_is_Writable"$this
done
Output with static docroot
DIR Found WITH FILES/var/www/html/test3 4
DIR Found WITH FILES/var/www/html/test3/abc 2
Writable_dir Empty/var/www/html/abc
DIR Found WITH FILES/var/www/html/test/abc 1
DIR Found WITH FILES/var/www/html/test2 1
Output with duynamic Docroot
"/var/www/html" "/var/www/test/www.example.com" "/var/www/www.example.com"\n
find: "/var/www: No such file or directory
find: "/var/www/test: No such file or directory
find: "/var/www: No such file or directory
"/var/www/html" "/var/www/test/www.example.com" "/var/www/www.example.com"\n
find: "/var/www: No such file or directory
find: "/var/www/test: No such file or directory
|
|
|||||
|
Your code is a little wrong there in your assigning multiple directories to the docroot and adding a newline. No need for the new line. Set confd to "$docroot" not "$docroot\n". When you do the find $confd it will put a newline in command line where it doesn't belong.
#while [ $i -le $doccount ] # do # confd="$docroot\n" #echo $confd confd="$docroot" find $confd -type d -perm /o=w | while read DIR which would be find /var/www/html /var/www/test/www.example.com /var/www/www.example.com -type d -perm /o=w | while read DIR |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|