The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-22-2008
aliahsan81 aliahsan81 is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 62
Question Loop problem with one more problem

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
  #2 (permalink)  
Old 09-22-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,365
Quote:
Originally Posted by aliahsan81 View Post
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.

Please use English in this forum. Write "you", not "u".
Quote:
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.

What does "not working" mean? What does happen? What do you want to happen?
Quote:
My code

Please put code inside [CODE] tags.
Quote:
Code:
docroot=$(grep -H DocumentRoot /etc/httpd/conf.d/*.conf |
 awk -F' ' '{ print $3 }'| sort -u | uniq)

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:


Code:
docroot=$(grep -H DocumentRoot /etc/httpd/conf.d/*.conf |
 awk -F' ' '!x[$3]++ { ++n } END { print n }'

Quote:
Code:
doccount=$(grep -H DocumentRoot /etc/httpd/conf.d/*.conf |
 awk -F' ' '{ print $3 }'| sort -u | uniq | wc -l)

for (( i=0; i <= $doccount; ++i ))

It is safer to stick to standard syntax:


Code:
i=0
while [ $i -le $doccount ]
do
   : whatever
   i=$(( $i + 1 ))
done

Quote:

Code:
 do
        confd="$docroot\n"

Code:
        confd="$docroot"

Quote:

Code:
echo $confd
        find $confd -type d -perm /o=w | while read DIR
do
do some thing 

done ## while done
done ##for done
  #3 (permalink)  
Old 09-23-2008
aliahsan81 aliahsan81 is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 62
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

  #4 (permalink)  
Old 01-07-2009
BubbaJoe's Avatar
BubbaJoe BubbaJoe is offline
Registered User
  
 

Join Date: Oct 2008
Location: St Louis
Posts: 153
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:13 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0