Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i awk all documnt root directorys in httpd.conf then mkdir img2 1

Status
Not open for further replies.

farley99

MIS
Feb 12, 2003
413
US
I want to grep all directories in the lines like
DocumentRoot /home/a/public_html

Then mkdir /home/username/public_html/img2 for everyones document root directory.

Got any tips?

<VirtualHost *>
ServerAdmin webmaster@emasdfsdf.org
DocumentRoot /home/a/public_html
User abefro
Group abefro
ServerName localhost
ScriptAlias /cgi-bin/ /home/a/public_html/cgi-bin/
</VirtualHost>
 
It tried that but go this error....
root@marge [/usr/local/apache/conf]# ./ss
awk: cmd. line:2: fatal: cannot open file `{' for reading (No such file or directory)
./ss: line 2: syntax error near unexpected token `&quot;'
./ss: line 2: ` system(&quot;mkdir &quot; $2 &quot;/img&quot;)'


Got any tips?
 
If you're just storing the program in a file, rather than executing it from the command line, then you need

Code:
#!/bin/awk -f
/^DocumentRoot/ {
  system(&quot;mkdir &quot; $2 &quot;/img&quot;)
}

If thats not it, you'd better post what's in your ./ss file


--
 
THANKS!!

How does it know $2 is the document root directory?
 
How do i chown it to the user?

#!/bin/awk -f
/^DocumentRoot/ {
system(&quot;mkdir &quot; $2 &quot;/img&quot;)
}
/^User/ {
system(&quot;chown &quot; $3.$3 &quot;/img&quot;)
}

That tells me...
chown: too few arguments
 
> How does it know $2 is the document root directory?
Read up on how AWK assigns input text to field variables

DocumentRoot /home/a/public_html
red is $1
green is $2

> How do i chown it to the user?
You can't really do that until you've seen the Group line in the file.
Group abefro

So you need to record some information within the AWK program from previous lines
Code:
#!/bin/awk -f

# get the root directory
# and append the image subdirectory name
/^DocumentRoot/ {
    directory = $2 &quot;/img&quot;
}

# get the user from the User line
/^User/ {
    user = $2
}

# get the group from the Group line
# and perform all the commands
/^Group/ {
    group = $2

    # now we have all we need
    system( &quot;mkdir &quot; directory )
    system( &quot;chown &quot; user &quot;:&quot; group &quot; &quot; directory )
}

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top