Loading

Monday, August 3, 2009

Linux Hosting Usage Measurement Shell Script

# Hosting Measurement Script by jim ballowe
### INSTRUCTIONS
##### CREATE DIRECTORIES
####### mkdir /root/bin
####### mkdir /root/bin/storage
##### CREATE SCRIPT
####### vi /root/bin/measure.sh
##### MAKE SCRIPT EXECUTABLE
####### chmod 744 /root/bin/measure.sh
##### Create soft links so that it runs weekly and monthly
####### ln -s /root/bin/measure.sh /etc/cron.weekly/measure.sh
####### ln -s /root/bin/measure.sh /etc/cron.monthly/measure.sh

### Define variables for naming the final backup file
DATE=`date +%Y%m%d-%H%M` # Datestamp e.g 20080109-2200
DOW=`date +%A` # Day of the week e.g. Monday
DNOW=`date +%u` # Day number of the week 1 to 7 where 1 represents Monday
DOM=`date +%d` # Date of the Month e.g. 27
M=`date +%B` # Month e.g January
W=`date +%V` # Week Number e.g 37
Y=`date +%Y`
VER=1.0 # Version Number

### TEST ECHO OF STRINGS (Uncomment for debugging)
# echo Date = "$DATE"
# echo Source = "$SOURCE"
# echo Target = "$TARGET"
# echo Age = "$AGE"

### WRITE OUTPUT TO FILE
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ > /root/bin/storage/"$DATE"_measure
echo "$HOSTNAME" MEASUREMENTS for "$M" "$DOM", "$Y" >> /root/bin/storage/"$DATE"_measure
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ >> /root/bin/storage/"$DATE"_measure
echo ==== CONTENT FULL "$HOSTNAME" ==== >> /root/bin/storage/"$DATE"_measure
du -sh /var/www/ >> /root/bin/storage/"$DATE"_measure
echo ~~~~~~~~~ Content Detail ~~~~~~~~~ >> /root/bin/storage/"$DATE"_measure
du -sh /var/www/* >> /root/bin/storage/"$DATE"_measure
echo ==== DATABASE FULL "$HOSTNAME" ==== >> /root/bin/storage/"$DATE"_measure
du -sh /var/lib/mysql/ >> /root/bin/storage/"$DATE"_measure
echo ~~~~~~~~~ Database Detail ~~~~~~~~ >> /root/bin/storage/"$DATE"_measure
du -sh /var/lib/mysql/* >> /root/bin/storage/"$DATE"_measure

No comments:

Post a Comment