2014年3月4日 星期二

nginx start shell script

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /opt/nginx/conf/nginx.conf
# pidfile:     /opt/nginx/logs/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/opt/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest || return $?
    stop
    start
}

reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac

rewirte list

##for 特定 jsp 導入 特定 url

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/ad\/trnaddrNum.jsp$
RewriteRule ^/ad\/trnaddrNum.jsp(.*)$      http://www.104.com.tw/jb/service/ad/TransferAddress/TransferCount$1  [R,L]
RewriteCond %{REQUEST_URI} ^/ad\/trnaddr.jsp$
RewriteRule ^/ad\/trnaddr.jsp(.*)$ http://www.104.com.tw/jb/service/ad/TransferAddress$1  [R,L]

###機車需求

RewriteRule     /104reading$                            /cfdocs/edu/104reading/index.cfm        [L,QSA,PT]
RewriteRule     /104reading/$                           /cfdocs/edu/104reading/index.cfm        [L,QSA,PT]
RewriteRule     /104reading/index.html$                 /cfdocs/edu/104reading/index.cfm        [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/info.html$       /cfdocs/edu/104reading/index.cfm        [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/index/info.html$ /cfdocs/edu/104reading/index.cfm        [L,QSA,PT]

RewriteRule     /cfdocs/edu/104reading/(.*)/kw(.*)/st(.*)/recorded/page(.*)/info.html   /cfdocs/edu/104reading/$1.cfm?kw=$2&st=$3&recorded&page=$4  [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/kw(.*)/st(.*)/recorded/info.html            /cfdocs/edu/104reading/$1.cfm?kw=$2&st=$3&recorded          [L,QSA,PT]

RewriteRule     /cfdocs/edu/104reading/(.*)/kw(.*)/recorded/page(.*)/info.html          /cfdocs/edu/104reading/$1.cfm?kw=$2&recorded&page=$3        [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/kw(.*)/recorded/info.html                   /cfdocs/edu/104reading/$1.cfm?kw=$2&recorded                [L,QSA,PT]

RewriteRule     /cfdocs/edu/104reading/(.*)/uno(.*)/orderType(.*)/tag(.*)/type(.*)/page(.*)/info.html           /cfdocs/edu/104reading/$1.cfm?uno=$2&orderType=$3&tag=$4&type=$5&page=$6        [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/j(.*)/theclass(.*)/school(.*)/orderType(.*)/page(.*)/info.html      /cfdocs/edu/104reading/$1.cfm?j=$2&theclass=$3&school=$4&orderType=$5&page=$6   [L,QSA,PT]

RewriteRule     /cfdocs/edu/104reading/(.*)/uno(.*)/orderType(.*)/showType(.*)/page(.*)/info.html       /cfdocs/edu/104reading/$1.cfm?uno=$2&orderType=$3&showType=$4&page=$5   [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/uno(.*)/orderType(.*)/type(.*)/page(.*)/info.html           /cfdocs/edu/104reading/$1.cfm?uno=$2&orderType=$3&type=$4&page=$5       [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/uno(.*)/orderType(.*)/tag(.*)/page(.*)/info.html            /cfdocs/edu/104reading/$1.cfm?uno=$2&orderType=$3&tag=$4&page=$5        [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/uno(.*)/orderType(.*)/tag(.*)/type(.*)/info.html            /cfdocs/edu/104reading/$1.cfm?uno=$2&orderType=$3&tag=$4&type=$5        [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/j(.*)/theclass(.*)/school(.*)/orderType(.*)/info.html       /cfdocs/edu/104reading/$1.cfm?j=$2&theclass=$3&school=$4&orderType=$5   [L,QSA,PT]

RewriteRule     /cfdocs/edu/104reading/(.*)/uno(.*)/orderType(.*)/page(.*)/info.html            /cfdocs/edu/104reading/$1.cfm?uno=$2&orderType=$3&page=$4       [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/uno(.*)/orderType(.*)/type(.*)/info.html            /cfdocs/edu/104reading/$1.cfm?uno=$2&orderType=$3&type=$4       [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/uno(.*)/orderType(.*)/tag(.*)/info.html             /cfdocs/edu/104reading/$1.cfm?uno=$2&orderType=$3&tag=$4        [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/uno(.*)/orderType(.*)/showType(.*)/info.html        /cfdocs/edu/104reading/$1.cfm?uno=$2&orderType=$3&showType=$4   [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/j(.*)/theclass(.*)/school(.*)/info.html             /cfdocs/edu/104reading/$1.cfm?j=$2&theclass=$3&school=$4        [L,QSA,PT]

RewriteRule     /cfdocs/edu/104reading/(.*)/kw(.*)/st(.*)/info.html             /cfdocs/edu/104reading/$1.cfm?kw=$2&st=$3               [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/uno(.*)/fno(.*)/info.html           /cfdocs/edu/104reading/$1.cfm?uno=$2&fno=$3             [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/uno(.*)/orderType(.*)/info.html     /cfdocs/edu/104reading/$1.cfm?uno=$2&orderType=$3       [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/uno(.*)/tag(.*)/info.html           /cfdocs/edu/104reading/$1.cfm?uno=$2&tag=$3             [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/uno(.*)/type(.*)/info.html          /cfdocs/edu/104reading/$1.cfm?uno=$2&type=$3            [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/tag(.*)/page(.*)/info.html          /cfdocs/edu/104reading/$1.cfm?tag=$2&page=$3            [L,QSA,PT]

RewriteRule     /cfdocs/edu/104reading/(.*)/j(.*)/info.html     /cfdocs/edu/104reading/$1.cfm?j=$2      [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/kw(.*)/info.html    /cfdocs/edu/104reading/$1.cfm?kw=$2     [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/cno(.*)/info.html   /cfdocs/edu/104reading/$1.cfm?cno=$2    [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/nno(.*)/info.html   /cfdocs/edu/104reading/$1.cfm?nno=$2    [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/uno(.*)/info.html   /cfdocs/edu/104reading/$1.cfm?uno=$2    [L,QSA,PT]
RewriteRule     /cfdocs/edu/104reading/(.*)/tag(.*)/info.html   /cfdocs/edu/104reading/$1.cfm?tag=$2    [L,QSA,PT]

rsyslog conf

$ModLoad imtcp.so
$ModLoad ommysql
:syslogtag, contains, "nmbd"  ~

$template manphp,"insert into $Groupname (Message, Facility, FromHost, Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values ('%msg%', %syslogfacility%, '%HOSTNAME%', %syslogpriority%, '%timereported:::date-mysql%', '%timegenerated:::date-mysql%', %iut%, '%syslogtag%')",SQL
$template cmdlog,"insert into $Groupname (Message, Facility, FromHost, Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values ('%msg%', %syslogfacility%, '%HOSTNAME%', %syslogpriority%, '%timereported:::date-mysql%', '%timegenerated:::date-mysql%', %iut%, '%syslogtag%')",SQL
$template securelog,"insert into $Groupname (Message, Facility, FromHost, Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values ('%msg%', %syslogfacility%, '%HOSTNAME%', %syslogpriority%, '%timereported:::date-mysql%', '%timegenerated:::date-mysql%', %iut%, '%syslogtag%')",SQL

#define web group
+(servername)
##bypass log policy##
:msg, contains, "DBERROR:"  ~
##custom log policy##
:msg, contains, "attackalert:" >(IPADDR),linuxlog,rsyslog,(password);$Groupname
:msg, contains, "exec_command:" >(IPADDR),cmdlog,rsyslog,(password);cmdlog
if $syslogtag == 'rsyslogd:' then >(IPADDR),linuxlog,rsyslog,(password);$Groupname
if $syslogtag == 'MD5:' then >(IPADDR),linuxlog,rsyslog,(password);$Groupname
if $syslogpriority == '4' then >(IPADDR),linuxlog,rsyslog,(password);$Groupname#warn
if $syslogpriority == '3' then >(IPADDR),linuxlog,rsyslog,(password);$Groupname#error
if $syslogpriority == '2' then >(IPADDR),linuxlog,rsyslog,(password);$Groupname#crit
if $syslogpriority == '1' then >(IPADDR),linuxlog,rsyslog,(password);$Groupname#alert
if $syslogpriority == '0' then >(IPADDR),linuxlog,rsyslog,(password);$Groupname#emerg
##standard log policy##
authpriv.*  >(IPADDR),securelog,rsyslog,(password);securelog
##web group setting end##



============db ===========
cmdlog

CREATE TABLE `3phd` (
`ID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`CustomerID` BIGINT(20) NULL DEFAULT NULL,
`ReceivedAt` DATETIME NULL DEFAULT NULL,
`DeviceReportedTime` DATETIME NULL DEFAULT NULL,
`Facility` SMALLINT(6) NULL DEFAULT NULL,
`Priority` SMALLINT(6) NULL DEFAULT NULL,
`FromHost` VARCHAR(60) NULL DEFAULT NULL,
`Message` TEXT NULL,
`NTSeverity` INT(11) NULL DEFAULT NULL,
`Importance` INT(11) NULL DEFAULT NULL,
`EventSource` VARCHAR(60) NULL DEFAULT NULL,
`EventUser` VARCHAR(60) NULL DEFAULT NULL,
`EventCategory` INT(11) NULL DEFAULT NULL,
`EventID` INT(11) NULL DEFAULT NULL,
`EventBinaryData` TEXT NULL,
`MaxAvailable` INT(11) NULL DEFAULT NULL,
`CurrUsage` INT(11) NULL DEFAULT NULL,
`MinUsage` INT(11) NULL DEFAULT NULL,
`MaxUsage` INT(11) NULL DEFAULT NULL,
`InfoUnitID` INT(11) NULL DEFAULT NULL,
`SysLogTag` VARCHAR(60) NULL DEFAULT NULL,
`EventLogType` VARCHAR(60) NULL DEFAULT NULL,
`GenericFileName` VARCHAR(60) NULL DEFAULT NULL,
`SystemID` INT(11) NULL DEFAULT NULL,
`ProcessID` INT(11) NULL DEFAULT NULL,
`Messagetype` VARCHAR(60) NULL DEFAULT NULL,
PRIMARY KEY (`ID`)
)
COLLATE='latin1_swedish_ci'
ENGINE=MyISAM
AUTO_INCREMENT=337;

===========================
linuxlog

CREATE TABLE `3phd` (
`ID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`CustomerID` BIGINT(20) NULL DEFAULT NULL,
`ReceivedAt` DATETIME NULL DEFAULT NULL,
`DeviceReportedTime` DATETIME NULL DEFAULT NULL,
`Facility` SMALLINT(6) NULL DEFAULT NULL,
`Priority` SMALLINT(6) NULL DEFAULT NULL,
`FromHost` VARCHAR(60) NULL DEFAULT NULL,
`Message` TEXT NULL,
`NTSeverity` INT(11) NULL DEFAULT NULL,
`Importance` INT(11) NULL DEFAULT NULL,
`EventSource` VARCHAR(60) NULL DEFAULT NULL,
`EventUser` VARCHAR(60) NULL DEFAULT NULL,
`EventCategory` INT(11) NULL DEFAULT NULL,
`EventID` INT(11) NULL DEFAULT NULL,
`EventBinaryData` TEXT NULL,
`MaxAvailable` INT(11) NULL DEFAULT NULL,
`CurrUsage` INT(11) NULL DEFAULT NULL,
`MinUsage` INT(11) NULL DEFAULT NULL,
`MaxUsage` INT(11) NULL DEFAULT NULL,
`InfoUnitID` INT(11) NULL DEFAULT NULL,
`SysLogTag` VARCHAR(60) NULL DEFAULT NULL,
`EventLogType` VARCHAR(60) NULL DEFAULT NULL,
`GenericFileName` VARCHAR(60) NULL DEFAULT NULL,
`SystemID` INT(11) NULL DEFAULT NULL,
`ProcessID` INT(11) NULL DEFAULT NULL,
`Messagetype` VARCHAR(60) NULL DEFAULT NULL,
PRIMARY KEY (`ID`)
)
COLLATE='latin1_swedish_ci'
ENGINE=MyISAM
AUTO_INCREMENT=328279;


===============================
securelog

CREATE TABLE `3phd` (
`ID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`CustomerID` BIGINT(20) NULL DEFAULT NULL,
`ReceivedAt` DATETIME NULL DEFAULT NULL,
`DeviceReportedTime` DATETIME NULL DEFAULT NULL,
`Facility` SMALLINT(6) NULL DEFAULT NULL,
`Priority` SMALLINT(6) NULL DEFAULT NULL,
`FromHost` VARCHAR(60) NULL DEFAULT NULL,
`Message` TEXT NULL,
`NTSeverity` INT(11) NULL DEFAULT NULL,
`Importance` INT(11) NULL DEFAULT NULL,
`EventSource` VARCHAR(60) NULL DEFAULT NULL,
`EventUser` VARCHAR(60) NULL DEFAULT NULL,
`EventCategory` INT(11) NULL DEFAULT NULL,
`EventID` INT(11) NULL DEFAULT NULL,
`EventBinaryData` TEXT NULL,
`MaxAvailable` INT(11) NULL DEFAULT NULL,
`CurrUsage` INT(11) NULL DEFAULT NULL,
`MinUsage` INT(11) NULL DEFAULT NULL,
`MaxUsage` INT(11) NULL DEFAULT NULL,
`InfoUnitID` INT(11) NULL DEFAULT NULL,
`SysLogTag` VARCHAR(60) NULL DEFAULT NULL,
`EventLogType` VARCHAR(60) NULL DEFAULT NULL,
`GenericFileName` VARCHAR(60) NULL DEFAULT NULL,
`SystemID` INT(11) NULL DEFAULT NULL,
`ProcessID` INT(11) NULL DEFAULT NULL,
`Messagetype` VARCHAR(60) NULL DEFAULT NULL,
PRIMARY KEY (`ID`)
)
COLLATE='latin1_swedish_ci'
ENGINE=MyISAM
AUTO_INCREMENT=328279;

==========================
winlog

CREATE TABLE `backer` (
`ID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`CustomerID` BIGINT(20) NULL DEFAULT NULL,
`ReceivedAt` DATETIME NULL DEFAULT NULL,
`DeviceReportedTime` DATETIME NULL DEFAULT NULL,
`Facility` SMALLINT(6) NULL DEFAULT NULL,
`Priority` SMALLINT(6) NULL DEFAULT NULL,
`FromHost` VARCHAR(60) NULL DEFAULT NULL,
`Message` TEXT NULL,
`NTSeverity` INT(11) NULL DEFAULT NULL,
`Importance` INT(11) NULL DEFAULT NULL,
`EventSource` VARCHAR(60) NULL DEFAULT NULL,
`EventUser` VARCHAR(60) NULL DEFAULT NULL,
`EventCategory` INT(11) NULL DEFAULT NULL,
`EventID` INT(11) NULL DEFAULT NULL,
`EventBinaryData` TEXT NULL,
`MaxAvailable` INT(11) NULL DEFAULT NULL,
`CurrUsage` INT(11) NULL DEFAULT NULL,
`MinUsage` INT(11) NULL DEFAULT NULL,
`MaxUsage` INT(11) NULL DEFAULT NULL,
`InfoUnitID` INT(11) NULL DEFAULT NULL,
`SysLogTag` VARCHAR(60) NULL DEFAULT NULL,
`EventLogType` VARCHAR(60) NULL DEFAULT NULL,
`GenericFileName` VARCHAR(60) NULL DEFAULT NULL,
`SystemID` INT(11) NULL DEFAULT NULL,
`ProcessID` INT(11) NULL DEFAULT NULL,
`Messagetype` VARCHAR(60) NULL DEFAULT NULL,
PRIMARY KEY (`ID`)
)
COLLATE='latin1_swedish_ci'
ENGINE=MyISAM
AUTO_INCREMENT=62719136;

for do done (openstack scrit)

type=web
for i in 17

do
   echo "nova-manage service disable $type-cp$i nova-compute"
   nova-manage service disable $type-cp$i nova-compute
   echo "nova-manage service disable $type-cp$i nova-network"
   nova-manage service disable $type-cp$i nova-network
done

nova-manage service list


2013年9月26日 星期四

mount remount

mount -o remount,rw /


很簡單的一個remount 成可讀寫的file system ,但前題下,

要做時最好要先進 single user mode 丫丫丫丫丫~~~~~~~

PS: 當 FSTAB 掛載不到會進入一個要求你KEY root 密碼,那其實不是 single user mode 




2013年9月12日 星期四

Sed 運用

在每一行的行尾增加字符
sed -i 's/\($\)/aaa/g' /home/test.txt

#每行首增加 #
sed -i 's/\(^\)/#/g' /home/test.txt

 #替換第一.字符成#
sed -i 's/\(^.\)/#/g' /home/test.txt

搜尋 time 區間
sed -n '/2012:02:20:00/,/2012:02:50:00/p' /opt/httpd/logs/io_access_log20121019 | awk '{if ( $(NF-1) > '1000000' )print $0}'



2012年8月6日 星期一

shell script function 範例



Starttomcat(){
               
               /opt/tomcat/bin/start.sh

}



CHECK_START() {
                sleep 5
                STATUS=`tail -n 10 $INSTENCE_LOG | grep -c "Server startup in"`
                if [ "$STATUS" -eq "1" ];then
                        echo tomcat restart OK
                        CHECK_IPTABLE
                   else
                        Killtomcat
                        sleep 1
                        Starttomcat
                        CHECK_START
                fi
}


case $1 in
start)
        Starttomcat
        CHECK_START
#       StartApache
        ;;
stop)
        Killtomcat
        ;;
restart)
        Killtomcat
        sleep 1
        Starttomcat
        CHECK_START
        ;;
*)
        echo $"Usage: {start|stop|restart}"
        exit 1
        ;;
esac