Alecs’s blog
Fii linux! Descarca-te de problemele neimportante din memorie!

The main ideea of this script is that if it is set up in crontab, it will check if your root partition is filled up of logs… if so, then it will backup some logs into home partition, and after that will truncate all main files and will erase old logrotate logs.

for the moment the script will do these actions if your free space is lower than 1G (if [[ $var < 1.0 ]] )

After the job done, it will send you a mail and it will tell you how much free space you had before run the script, and how much do you have now.
#!/bin/bash

#
# Version 1.0
# Script done by Lupu Alexandru
#
# You may add any modifications.
# This script is meant to check if the root partition is almost filled up.
# If it is filled up, then backup the logs and clear that partition
#

# MUST NOT BE / or any filesystem type (ext2, ext3, jfs, etc.)

looking_for=”your root filesystem label or size ”
date=`date +%Y%m%d`
path=/home/logs/$date
# main script
str=`df -h | grep $looking_for | awk ‘{print $4}’ `
var=${str/G/}
SUBJECT=”Automated Mail Alert”
MESSAGE=”/tmp/message.txt”
EMAILADDR=”your address here ”
#we check if requiered directories exists
function directory {
if [[ !( -d /home/logs/) ]]; then
mkdir /home/logs
fi
if [[ !( -d $path ) ]]; then
mkdir $path
fi
}

# we clean the mess in the /var/log/lighthttpd dir
function lighthttpd {
cd /var/log/lighthttpd/
tar czf $path/lighthttpd.tar.gz /var/log/lighthttpd/
echo “” > access.log
echo “” > error.log
}

# we clear the mess with maillogs in /var/log/
function maillogs {
cd /var/log/
tar czf $path/maillog.tar.gz /var/log/maillog*
echo “” > maillog
rm -f maillog.*
}

# we also clear the mess in /var/log/httpd
function httpds {
cd /var/logs/httpd/
tar zcf $path/httpd.tzr.gz /var/log/httpd/
echo “” > access_log
echo “” > error_log
echo “” > ssl_access_log
echo “” > ssl_error_log
echo “” > ssl_request_log
rm -f *.*
}

# we notify the project manager and the developer
function mails {

echo “The hard disk it was almost full. i had to make a copy of logs in $path.” >> $MESSAGE
echo “Before my action there were $str available. ” >> $MESSAGE
echo “Now there are `df -h | grep $looking_for | awk ‘{print $4}’` available. “>> $MESSAGE
echo “Please correct this issue ASAP” >> $MESSAGE
echo “Time: `date`” >> $MESSAGE

$(type -p mail) -s “$SUBJECT” “$EMAILADDR” < $MESSAGE

rm $MESSAGE
}

if [[ $var < 1.0 ]]; then
directory
lighthttpd
maillogs
httpds
mails
fi


Tags: , ,
May
11.

I decided to write this post in english because it might be utile to more people this way.

Recent experience, tough me that a good database structure is not enough when your site increases number of visitors exponential without possibility to have any time to rewrite the code or restructure your database model.

The whole ideea is to make a decisional system (algorithm) that decides whatever you use: cache system or block system. If your system uses block system, then is mandatory to generate the cache.

In the next rows i will try to present you some cache methods that are quite useful.

1. Caching the whole page
This is not a good practice when you have an online store or you have an application that requires a lot of information from database, but it can be useful for the site applications that have a lot of pages and a big number of visitors. The whole ideea is to keep your database server as free as possible. This way you can cache any page that is not often changed. A page like that can be stored with a big time buffer (example you regenerate that page twice or once per day).

For a page that is often modified, you can set the cache buffer somewhere below, i mean you could regenerate that page 1 per hour or you can generate it 6 times per hour. If the page is very often modified or it need to take online users or a number that has a small interval of changing, this time can be reduced to any measure.

2. Caching page sections

This ideea is similar with first one, but instead caching all the page, you might simply cache just a part of your web page … that means you will be able to control your modules that are grouped in one page more easily and they could have separate cache lifetime. You might be intrested to cache 3 modules in this way. 1 module with a cache life time around 10 minutes, 2nd module with a cache lifetime of 1 day, and 3rd with a cache of 1 week.

3. Caching variables

This one might be a good option for the sites with a great number of visitors, but its content is changing often. in this case you can cache each variable as a file, or the entire set of variables into a file. Either you cache one variable or you write them all in a single file, result will be the same.

3.1. Storing all variables in a single file

If you choose this type of caching then you must be aware that is the best for you separate yor sql queries / results from the process code. This way you can have a bigger control over your cache system. Also is more easy to generate your cache. Must be aware that your php structure will create separate including files that will be generated at a specified time … or simply, to make them permanent, you set them to expire in 1.. 2 ..100 years.

<?php

$variable1 = “foo_value”;

$variable2 = “foo2_value”;

?>

3.2. Storing all variables in multiple files

This way, you will not be forced to separate your sql queries, but your code will be more complicated because you will be “forced” to write more decisional conditions in your code. This can be a mess when you try to echo more variables in a single row or something like that. A second strategy would be to make a function with some paramehers like:
function my_cache_function($path_to_file,$time,$expression){
// a decisional if
if (file_exists($path_to_file) && (filectime($path_to_file)>(date(”U”)-$time))){
$my_cached_var = file_get_contents($path_to_file);
}else{
eval(\$my_cached_var = $expession);
unlink($path_to_file);
file_put_contents($path_to_file,$my_cached_var);
}
return $my_cached_var;
}

this function will allow you to write in your code expressions like:
$messages = my_cache_function(”./cache_dir/messages.cache”,60,” mysql_result(mysql_query(\”SELECT count(*) as nr FROM my_messages_table WHERE my_field=’{$user_id}’\”),0,\”nr\”)”);

In the example below i’ve shown how can you cache a variable for a time of 60 seconds. Of course, the main ideea of a cache system is to get some variables that remain constant for a long period, or they consumes a lot of resources to be shown.

3.3 Using memcached.

By using memcached, you will be able to store the variable into ram memory for a long time period.

I haven’t checked all the versions, but, if you test my ideea/ script that is presented here, you are doing at your own risk.


Tags: , , ,
May
11.

Hi there!

Almost 2 or 3 years ago i’ve found qmail MTA and suite. The bad part is that the qmail is hard to configure if you are a newcomer in linux / qmail. All the tings you have to is to search in google for qmailrocks and you will find a cool place where to start, with a nice tutorial and a good and maintained mail list.

As ubuntu/ debian user, i am triing to make a script that will do your life easier. I am planning to make a script (started to work at it), that will provide you qmail rocks full flavour, including all packages, features and patches that you need to run to configure it.

I hope i will post it here asap, depends on my free time (if i have any… )


Tags: , , ,

Bergenbier a lansat “moda” de a sarbatori ziua barbatului pe data de 5 Mai.

Tzeapa cea mai mare este ca si de Ziua Barbatului, dar si de Ziua Femeii tot Dobitocul de barbat plateste…

Abia astept sa vad ziua in care Femeia va veni la Barbat cu o lada de bere sau cu o stripteoza, sau sa il lase nestingherit sa flueire, “sa-si rupa gatul” dupa altele …

Pana atunci, Barbatul se prezinta in fiecare zi de 1 sau 8 Martie cu buchetul de zarzavaturi, animalul de plus, si 2 bilete la un film romantic…

Cata nedreptate.


Tags:

Powered by Wordpress
Theme © 2005 - 2009 FrederikM.de
BlueMod is a modification of the blueblog_DE Theme by Oliver Wunder