Register
It is currently Thu Nov 27, 2014 11:07 am

Script to 'walk' all non-default apache installs and tar...


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Mon May 07, 2012 10:23 am   
User avatar

Joined: Fri Jul 22, 2011 5:39 pm
Posts: 47
I call this "Grab That Apache" or GTA. :)
I wanted to 'walk' all non-default apache installs on my CentOS|Ubuntu hosts and tar up the appropriate directory...
Since we only have two OSs to be concerned with, I wanted a generic script and here's what I made...

Code:
#!/bin/bash
### Author:   JJ of cirrhus9.com
### Purpose:   Get non-default Apache installs and tar them up by Name
### Date:    05-07-2012
### Modified:   1336407790

### OS Check
grep -iq "CentOS" /proc/version
if [ $? = '0' ];then
OS="CentOS"
cd /c9backups
echo \#\!/bin/bash > gta.sh
chmod 700 gta.sh
TARDATE=$(date '+%m-%d-%Y.%s')
APACHEPROGBASE=$(grep -h "Alias /" /etc/httpd/conf.d /etc/httpd/conf/ -R  | egrep -v "home|ScriptAlias|#|doc|error|icons|javascript" | awk '{print $1 " "$2 " "$3}' | sed -e 's/Alias \///g' | sed -e 's/"//g')
echo "$APACHEPROGBASE" | while read col1 col2 ; do echo "/bin/tar -pzcf" "$col1"_"$TARDATE".tar.gz "$col2" ;done >> gta.sh
/c9backups/gta.sh
else
OS="Ubuntu"
cd /c9backups
echo \#\!/bin/bash > gta.sh
chmod 700 gta.sh
TARDATE=$(date '+%m-%d-%Y.%s')
APACHEPROGBASE=$(grep -h "Alias /" /etc/apache2/*.conf /etc/apache2/conf.d/*.conf -R  | egrep -v "home|ScriptAlias|#|doc|error|icons|javascript" | awk '{print $1 " "$2 " "$3}' | sed -e 's/Alias \///g' | sed -e 's/"//g')
echo "$APACHEPROGBASE" | while read col1 col2 ; do echo "/bin/tar -pzcf" "$col1"_"$TARDATE".tar.gz "$col2" ;done >> gta.sh
/c9backups/gta.sh
fi


It still needs error handling, a reporting feature, and a rotation of the number of copies to keep, But it works as is.

Enjoy.


Top
 Profile WWW  
 PostPosted: Mon May 07, 2012 4:00 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 571
hi,

`$?' is an integer, use arithmetic tests.
why not directly `test grep'?
TARDATE doesn't depend on a condition, so doesn't two previous commands.
based on the OS condition, the code is the same except filenames, use a function and give it those filenames as arguments.
why build another script, use a loop here.

generally speaking,
when you see code is not indented, it's not good.
when code lines are more than 80 characters, it's not good.
when you see a command 'piping' to another instance of itself, it's not good.
when you see `grep | awk (| sed )', in any order, it's not good; use awk only.

HTH.


Top
 Profile  
 PostPosted: Tue May 08, 2012 6:57 am   
User avatar

Joined: Fri Jul 22, 2011 5:39 pm
Posts: 47
I have 3 brain cells left and two of those are fighting? And I'm lucky it runs at all. :)

I posted my query here... and
here so I went with the advice/suggestion in post #2 in the first link.

Could it be "better"? Most certainly!
But I can always seek to improve it after it starts doing its intended task.

Generally speaking, when I hit "grep the grep grep" stuff, I start looking for another way.

Have a Great Day.


Top
 Profile WWW  
 PostPosted: Wed May 16, 2012 7:10 am   
User avatar

Joined: Fri Jul 22, 2011 5:39 pm
Posts: 47
I hate computers.

"Solution" deleted.

May 14, 2012 I found my grab_mysql function isn't working on CentOS release 5.8 Final.
I have to check mount perms options from/for fstab.


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP