BashScripts.org
http://bashscripts.org/forum/

Script to 'walk' all non-default apache installs and tar...
http://bashscripts.org/forum/viewtopic.php?f=7&t=1588
Page 1 of 1

Author:  Habitual [ Mon May 07, 2012 10:23 am ]
Post subject:  Script to 'walk' all non-default apache installs and tar...

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.

Author:  Watael [ Mon May 07, 2012 4:00 pm ]
Post subject:  Re: Script to 'walk' all non-default apache installs and tar

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.

Author:  Habitual [ Tue May 08, 2012 6:57 am ]
Post subject:  Re: Script to 'walk' all non-default apache installs and tar

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.

Author:  Habitual [ Wed May 16, 2012 7:10 am ]
Post subject:  Re: Script to 'walk' all non-default apache installs and tar

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.

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com