Linux Command rpm

delete rpm packages ignoring dependent error

#rpm -e –nodeps openssl-0.9.7a-33.17

list all files installed by a package
rpm -ql package_name

LVM

Setup lvm

combine /dev/sdb and /dev/sdc

if there’s partition on /dev/sdb, /dev/sdc, need to clear them first using fdisk

fdisk /dev/sdb -> d (delete partition) ->w

fdisk /dev/sdc

pvcreate /dev/sdb

pvcreate /dev/sdc

vgcreate vgrp /dev/sdb /dev/sdc

vgchange -a y vg

vgdisplay vg|grep ‘Total PE’
lvcreate -i2 -I8 -l 70006 vg -n lv

vgdisplay vg|grep ‘Total PE

‘lvcreate -i2 -I8 -l 70006 vg -n lv

mkfs.ext3 /dev/vg/lv

tune2fs -r 128000 /dev/vg/lv

mount /dev/vg/lv /backup

Remove lvm

#lvremove /dev/vg/lv
#vgremove vg
#fdisk /dev/sdb
#mkfs.ext3 /dev/sdb1
#tune2fs -r 128000 /dev/sdb1
(do same to /dev/sdc)
#mount /dev/sdb1 /www

Logrotate

Some logrotate  are not working properly

added “/var/log/xxx/*/errors” into /etc/logrotate.d/xxx
and change to weekly

/usr/local/zeus/web/log/errors /var/log/xxx/*/errors {
weekly
rotate 8
missingok
create 0644 nobody nobody
compress
}

problem in search

problem when search for “V&R”
V%26amp%3BR
%26 -> &
%3B -> ;
%26amp%3B -> &

Solution: change & to encoded code in query sent to html
Add:
$srch_name=eregi_replace(“&”,”%26amp%3B”,$srch_name);
before the following code
if($srch_name !=”){ $req.=”&name=$srch_name”; }
if($srch_site !=”){ $req.=”&site=$srch_site”; }

Posted in PHP

missing ; before statement

To check Javascript error, use Firefox Web Developer Addon

Tool -> Error Console

Got javascript error as “missing ; before statement” although there was no missing “;”

Finally found the reason is that the javascript function used number at the beginning, like

2way_func = function(){ …..}

Posted in PHP

awk & Sed

Calculate sum of the file size

ls -l access_log.2008-12-20*|gawk ‘{a+=$5;} END {print a;}’

 

Edit special lines using regular expression

awk ‘/aaa/ ‘ filename

 

Change file names using sed

##Example: from access_log.2008-12-20.01.gz.1  to access_log.2008-12-20.01.1.gz

for file in `ls access_log.2008-12-20.*`

do

newname=`echo $file|sed ‘s/\(access_log.2008-12-20.[0-9][0-9]\).gz.\([0-9]*\)/\1.\2.gz/’`

size=`ls -l $file|awk ‘{print $5}’`

if [ $size -gt 100 ];then

  echo “$file-> $newname”

fi

mv -v $file $newname

done

trim

trim

get rid of space, \n  and \r, etc

$login = trim($_POST[‘user_login’]);

Posted in PHP

Arrays in PHP

To define an Array

$prod = array();
$prod = array(“a”,”b”,”c”);

$prod = array(
“prod1” => array(“id”=>”prod001″,”date” => “111208”, “name”=>”aaa”);
“prod2” => array(“id”=>”prod002″,”date” => “111108”, “name”=>”bbb”);
“prod3 => array(“id”=>”prod003″,”date” => “111008”, “name”=>”ccc”);
);

$data=array();
$data[‘id’] = 1;
$data[‘name’] = ‘John’;

To read values out

foreach($SITE as $key1 => $val1){

foreach($sval1 as $key2 => $val2){

if($key2==”id”) echo “ID: $val2[0]\n”;

}

}

foreach($data as $value){

echo $value.”\n”;

}

Push elements into Array

Posted in PHP

bash — if

#!/bin/bash
if [ -n "$1" ];then
    filename = $1;
else
    filename = date --date='1 hour ago'" + %Y-%m-%d.%H"`;
fi

Compare numbers with -gt -lt -ne -eq

if [ “${size}” -gt 100 ];then
  echo $size
fi

Compare strings with = !=

if [ “${domain}” = “lalife.net” ];then
echo “correct”
fi
(#if [ “${domain}”=”lalife.net” ];then (##this won’t work without space around “=” or “!=”)

When using [[ ]]
if [[ ${domain} = “lalife.net” ]];then
echo “correct”
fi

([ ] needs the variable to be inside of “”)

Match
if [[ ${domain} =~ “lalife.net” ]];then
echo “correct”
fi
([ ] doesn’t work with =~)