Archive

Archive for August, 2010

Solved:mod_fcgid: /var/www/virtual/domain.tld/htdocs/index.php total process count 8 >= 8, skip the spawn request:ispcp

August 31st, 2010 No comments

mod_fcgid: /var/www/virtual/linksoflondonuk.com/htdocs/index.php total process count 8 >= 8, skip the spawn request
Method to solve:
vim /etc/apache2/mods-available/fcgid_ispcp.conf,and 33gg to line 33,modify MaxProcessCount 8 to a larger value:like,MaxProcessCount 10.

Categories: IT Architecture, Linux, Systems Tags:

Bash Reference Manual download,pdf and html format

August 30th, 2010 2 comments

60,878 words.Very detailed and useful for you to learn bash shell scripting.Digest it!
wc -w <<<`man bash`
bash.htm(right click and save it)
bash.pdf(right click and save it)

linux bash shell auto switch lowercase-uppercase

August 29th, 2010 No comments

Functionality:

Switch lowercase-uppercase from files given in parameters:
#if.sh -u aaa.txt bbb.txt #aaa.txt.UC bbb.txt.UC=>UPPERCASE
#if.sh -l aaa.txt bbb.txt #aaa.txt.LC bbb.txt.LC=>lowercase
Here goes the script:
#!/bin/sh
#if.sh -u aaa.txt bbb.txt #aaa.txt.UC bbb.txt.UC=>turn to upper case
#if.sh -l aaa.txt bbb.txt #aaa.txt.LC bbb.txt.LC=>turn to lower case
FILES=""
TRCASE=""
EXT=""
OPT=no

error_msg()
{
_FILENAME=$1
echo "`basename $0`: Error the conversion failed on $_FILENAME"
}

if [ $# -eq 0 ];then
echo "for more info try `basename $0` --help"
exit 1
fi

while [ $# -gt 0 ]
do
case $1 in
-u)TRCASE=upper
EXT=".UC"
OPT=yes
shift
;;
-l)TRCASE=lower
EXT=".LC"
OPT=yes
shift
;;
-help)echo "conver a file(s) to uppercase from lowercase"
exit 0
;;

-*)echo "usage: `basename $0` -[l|u] file [file..]"
exit 1
;;

*)if [ -f $1 ]
then
FILES=$FILES" "$1
else
echo "`basename $0`:Error cannot file"
fi
shift
;;
esac
done

if [ "$OPT" = "no" ]
then
echo "`basename $0`:errot you need to specify an option. No acton taken"
echo "try `basename $0` --help"
exit 1
fi

for LOOP in $FILES
do
case $TRCASE in
lower) cat $LOOP|tr "[a-z]" "[A-Z]" > $LOOP$EXT
if [ $? != 0 ]
then
error_msg $LOOP
else
echo "Converted ifle called $LOOP$EXT"
fi
;;
upper) cat $LOOP|tr "[A-Z]" "[a-z]" >$LOOP$EXT
if [ $? != 0 ]
then
error_msg $LOOP
else
echo "Converterd file called $LOOP$EXT"
fi
;;
esac
done

rpm(centos),apt-get(debian) auto detect and uninstall packages(bash shell)

August 27th, 2010 No comments

Here goes the thinking:First,use rpm -qa or apt-cache policy to find the name of the package(s) to remove.Then,use rpm -e or apt-get remove to uninstall the packages.
Detect the os type by bash shell:http://www.doxer.org/linux-shell-centos-debian-ostype/
#centos begin
rpm -qa|grep httpd #under centos it's httpd,debian apache
if [ $? = '0' ];then
aa="`rpm -qa|grep httpd`" #get the full-name of the package
rpm -e $aa
fi

#debian begin
apt-cache policy apache2|grep "Installed: 2." -q
if [ #? = '0'];then
apt-get remove apache2
fi

Add user account in proftpd server(Privileges through setfacl &getfacl)

August 27th, 2010 No comments

After you've installed proftpd in centos or debian,add user account is the next step.Use groupadd and useradd command,and passwd to set a password,the new user is then ready to use ftp to log in the home directory(set home directory by 'useradd -d').
But sometimes,things are not that simple.Now you want the ftp user have specified privileges on some directories,and you are not allowed to change the old mod(for example,directories under /var/www/htdocs).If you encounter this,time for you to use acl(Access Control List) module of linux.
Here is the detailed steps:
groupadd test
useradd -g test -d /var/www/virtual -s /sbin/nologin test #-s /sbin/nologin disallow user to log in the system
passwd test
setfacl -m u:test:rwx /var/www/virtual #test now have mod rwx
getfacl /var/www/virtual

#In /etc/rc.local,type in setfacl -m u:test:rwx /var/www/virtual to run the command at boot time

#If you find no command setfacl,getfacl on your system,use yum install acl(centos),apt-get install acl(debian,ubuntu) to firstly install them.

PS:

You can read more about ACL in linux here https://wiki.archlinux.org/index.php/Access_Control_Lists

Auto backup mysql database and use ftp command to cron transfer(bash shell)

August 27th, 2010 No comments

Use mysqldump command to dump the database sql files,then merge it with site file sources to tar named suffixed by YYYYMMDD(year-month-day).Then use ftp protocal tranfering the tarball to your remote backup server.
Here goes the script:
#!/bin/bash
#wordpress_backup.sh,chmod +x wordpress_backup.sh
YYYY=`date +%Y`
MM=`date +%m`
DD=`date +%d`
filename="$YYYY$MM$DD"
mysqldump -h localhost -u root -p123456 --default-character-set=utf8 db1>/tmp/db1_${filename}.sql
mysqldump -h localhost -u root -p123456 --default-character-set=utf8 db2>/tmp/db2_${filename}.sql
tar zcvpPf /tmp/doxer_$filename.tar.gz /var/www/virtual/doxer.org /tmp/db1_${filename}.sql db2_${filename}.sql
# to your backup server
ftp -v -n xxx.xxx.xxx.xxx <<EOF
user  ftp@xxx.com password
binary
cd backup_sql #change directory on remote backup server
lcd /tmp #change directory on localhost
prompt
mput doxer_$filename.tar.gz #upload tarball
close
bye
EOF

At last,if you want to backup the files three times a week,use crond to accomplish it.Here is the usage:
crontab -e
Type in the following line at the end of it:
0 23 * * 0,2,4 /usr/local/wordpress_backup.sh
Save & quit.Use /etc/init.d/cron restart,and enjoy the convienience.

php recursively count files under directory

August 24th, 2010 No comments

Sometimes(seems all times),virtual host provider has a limitation of file number on you(inode issue),and you want to use php to count files under directory.Here is a script for you.

many.php

FileCount("wordpress&rmbweb&liang99&huainong&discuz&cms&book",true);//true to count in files that positioned the same directory as this php script.First param is directory name.Use & to seperate from each param.
echo $count;

function FileCount($dir,$include=false){
global $count;
$arr=explode('&',$dir);
foreach($arr as $val){
if(is_dir($val)&&file_exists($val)){
$ob=scandir($val);
foreach($ob as $file){
if($file=="."||$file==".."){
continue;
}
$file=$val."/".$file;

if(is_file($file)){
$count++;
}elseif(is_dir($file)){
FileCount($file);
}
}
}
}
if($include){
$pathinfo=pathinfo(__FILE__);
$ob2=scandir($pathinfo['dirname']);
foreach($ob2 as $val){
if($val=='.'||$val=='..'){
continue;
}
$file=$pathinfo['dirname'].'/'.$val;
if(is_file($file)){
$count++;
}
}
}
}

php recursively delete directorys

August 24th, 2010 No comments

When using utf8 or unicode charsets,you have the chance to find messy codes with your file or directory descriptor.And the worse,you'll find that you cann't delete files that has a messy code file descriptor.If you have root access to your server,just use rm -rf to delete them,but what would you do if you just have ftp access to it?Here goes the solution for you.
<?php
function _imagecache_recursive_delete($dir) {
$d = dir($dir);
if (is_dir($dir) && !is_link($dir)) {
if ($d = opendir($dir)) {
while (($entry = readdir($d)) !== false) {
if ($entry == '.' || $entry == '..') continue;
$path = $dir .'/'. $entry;
if (is_file($path)) unlink($path);
if (is_dir($path)) _imagecache_recursive_delete($path);
}
closedir($d);
}
return rmdir($dir);
}
return unlink($dir);
}
$dir='./wordpress/wp-content/uploads/2010/03/';
_imagecache_recursive_delete($dir);
?>

Solved:mysql without access to remote hosts

August 23rd, 2010 No comments

1.Firstly,find your mysql my.cnf configuration file:(mysql --help|grep "Default options are read" -1 #-1,show 1 line before and 1 line after the match line)
Default options are read from the following files in the given order:
/etc/mysql/my.cnf ~/.my.cnf /usr/etc/my.cnf
2.vim and 47gg to jump to the 47 line,comment away bind-address

3.log in mysql,and execute the following sql statement:
CREATE USER 'root'@'%';
GRANT ALL PRIVILEGES ON * . * TO 'root'@'%' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0
MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
SET PASSWORD FOR 'root'@'%' = PASSWORD( '******' ) #密码

Using bash shell to auto-detect linux OS types(centos,debian,others)

August 18th, 2010 3 comments

#!/bin/bash
#linux_type.sh
os="";
grep "centos" /etc/issue -i -q
if [ $? = '0' ];then
os='centos'
fi

grep "debian" /etc/issue -i -q
if [ $? = '0' ];then
os='debian'
fi

if [ $os = "" ];then
echo "not a valid system os"
exit 1
fi
Save the above code as linux_type.sh,chmod +x ./linux_type.sh.Then,execute the bash script to get the result.

Small fix to Google Syntax Highlighter for WordPress

August 15th, 2010 No comments

1.Where to put <pre></pre>

If you put source file in the 'Virsual' mode of your wordpress editor,you should then change to 'HTML' mode and enclose the source code with <pre></pre>.

2.About <pre> name='code'(use <pre lang='code'> to substitute <pre name='code'>)

By defualt,Google Syntax Highlighter for WordPress use <pre name='code'> to declare it's css's beginning.However,you'll find the 'name' attribute lost when you switching from Virsual to HTML.We can solve the problem by using the W3C standard attribute of <pre> tag,that is <pre lang='code'>.

Here are the steps:

Find wp-content/plugins/google-syntax-highlighter/Scripts/shCore.js,locate to line 364,substitute
<pre class="html" lang="code">if(_73[i].getAttribute("name")==_71){</pre>
to<!--more-->
<pre class="html" lang="code">if(_73[i].getAttribute("lang")==_71){</pre>
And that's all about the revision.Afterwards,use <pre lang="code" class="..."> when you want to highlight your code.

Apache server statistics:SetHandler,.htaccess,server-info,server-status

August 11th, 2010 No comments

<Files "server-info.php">
SetHandler server-info
</Files>

<Files "server-status.php">
SetHandler server-status
</Files>
Just put them in one of your .htaccess files,and then access the file:

http://yourdomain.tld/server-info.php

http://yourdomain.tld/server-status.php

you'll see the lamp server configure infomation and the current status of your server(how many concurrent people on your site,etc.).