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
Please use English in this forum. Write "you", not "u".
What does "not working" mean? What does happen? What do you want to happen?
Please put code inside
tags.
docroot=$(grep -H DocumentRoot /etc/httpd/conf.d/*.conf |
awk -F' ' '{ print $3 }'| sort -u | uniq)
[/quote]
[indent]
You don't need uniq; you have already removed duplicates with sort -u.
In fact, you don't need sort, either. It can be done with awk alone:
docroot=$(grep -H DocumentRoot /etc/httpd/conf.d/*.conf |
awk -F' ' '!x[$3]++ { ++n } END { print n }'
It is safer to stick to standard syntax:
i=0
while [ $i -le $doccount ]
do
: whatever
i=$(( $i + 1 ))
done
confd="$docroot"
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.
#!/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