Category Archives: Source

16位のunicode番号を読む

#!/bin/bash

cat /dev/stdin | while read -r line
do
for word in $line
do
/usr/bin/printf $word;
echo -n ” “;
done
echo “”;
done

HAproxy-Keepalived自動インストール配置shell

#!/bin/bash
##################################
haproxy_path=/usr/local/haproxy
haproxy_conf=/usr/local/haproxy/conf/haproxy.cfg
#############haproxy-install#####################
cd /tmp
tar xvf haproxy-1.4.*.tar.gz
if [ $? -eq 0 ];then
echo “haproxy tar ok”
else
echo “haproxy tar no”
exit
fi
sleep 5
yum install gcc openssl openssl-devel make kernel-devel popt-devel openssl -y
cd /tmp/haproxy-*
make TARGET=linux26 PREFIX=$haproxy_path install
if [ $? -eq 0 ];then
echo “haproxy install ok”
else
echo “haproxy install no”
exit
fi
cd $haproxy_path
mkdir conf logs
touch $haproxy_path/conf/haproxy.cfg
#################haproxy.cfg#########################
echo -e “global\n\tlog 127.0.0.1 local0\n\tmaxconn 65535\n\tchroot $haproxy_path\n\tuser nobody\n\tgroup nobody\n\tdaemon\n\tnbproc 8\n\tpidfile $haproxy_path/haproxy.pid\n” > $haproxy_conf

echo -e “\ndefaults\n\tlog 127.0.0.1 local3\n\tmode http\n\toption httplog\n\toption dontlognull\n\toption redispatch\n\tretries 2\n\tmaxconn 2000\n\tcontimeout 5000\n\tclitimeout 50000\n\tsrvtimeout 50000” >> $haproxy_conf

echo -e “\nlisten web 0.0.0.0:80\n\tmode http\n\tbalance roundrobin\n\tcookie SERVERID insert indirect nocache\n\toption httplog\n\tlog global\n\toption httpchk HEAD /index.html HTTP/1.0” >> $haproxy_conf

read -p “Requires several server ” server
for ((i=1;i<=$server;i++)) do read -p "server ip " ip echo -e "server server$i $ip:80 cookie $i check inter 2000 rise 2 fall 5" >> $haproxy_conf
done
###########################keepalived###############################
mandir=/usr/local/src/man
kernel=$(uname -r)
keepalived_conf=/etc/keepalived/keepalived.conf
################################
cd /tmp
tar -xvf keepalived*.tar.gz
cd /tmp/keepalived-*
#############keepalived make##################
./configure –prefix=/ –mandir=$mandir –with-kernel-dir=/usr/src/kernels/$kernel*
if [ $? -eq 0 ];then
make
if [ $? -eq 0 ];then
make install
if [ $? -eq 0 ];then
echo “keepalived ok”
else
echo “keepalived no”
exit
fi
else
echo “keeplaived make no”
exit
fi
else
echo “keelalived make no”
fi

touch /etc/keepalived/keepalived.conf
########################################################
read -p “NIC binding ” network
####################keepalived.conf#####################
#############Global configuration#######################
echo -e ” ! Configuration File for keepalived\nglobal_defs {\n\tnotification_email {\n\tjqbash@gmail.com\n\t}\n\tnotification_email_from root@localhost\n\tsmtp_server 127.0.0.1\n\tsmtp_connect_timeout 30\n\trouter_id HAproxy\n}” > $keepalived_conf
############Virtual IP Configuration####################
read -p “Requires several server ” server
for ((a=1;a<=$server;a++)) do read -p "MASTER of BACKUP " states read -p "priority " priority read -p "virtual_router id " id read -p "vip address " vip echo -e "vrrp_instance VI_$a {\n\tstate $states\n\tinterface $network\n\tvirtual_router_id $id\n\t priority $priority\n\tadvert_int 1\n\tauthentication {\n\tauth_type PASS\n\tauth_pass tdoa\n\t}\n\tvirtual_ipaddress {\n\t$vip/24 dev $network\n\t}\n}" >> $keepalived_conf
done
#######################################################
/usr/local/haproxy/sbin/haproxy -f $haproxy_conf
/etc/rc.d/init.d/keepalived restart
#########################haproxy-keepalived.sh##############################
touch /etc/rc.d/haproxy-keepalived.sh
echo -e ‘#!/bin/bash\nwhile\t:\ndo\n haproxypid=ps -C haproxy --no-header | wc -l\n\tif [ $haproxypid -eq 0 ];then\n\t\t/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg\n\t\tsleep 5\n\thapropid=ps -C haproxy --no-header | wc -l\n\t\tif [ $hapropid -eq 0 ];then\n\t\t\t\t/etc/init.d/keepalived stop\n\t\tfi\n\tfi\n\tsleep 5\n proxypid=ps -C haproxy --no-header | wc -l\n\tif (($proxypid!= 0));then\n\t\t/etc/init.d/keepalived start\n\tfi\n\tsleep 5\ndone’ > /etc/rc.d/haproxy.sh
#############################################################################
chmod +x /etc/rc.d/haproxy.sh
/usr/bin/nohup /etc/rc.d/haproxy.sh &
rc_local=/etc/rc.local
echo ‘/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg’ >> $rc_local
echo ‘/etc/rc.d/init.d/keepalived start’ >> $rc_local
echo ‘/usr/bin/nohup /etc/rc.d/haproxy.sh &’ >> $rc_local
############################################################################

バッチ処理でn階段の魔方陣を出力する

@echo off
:start
set /p n=Please input your odd integer:
set /a p=n%%2
if %p% equ 0 echo Input error!&&goto start

set /a i=%n%
set /a t=(%n%+1)/2
set /a a%t%_%n%=1,temp=1,m=n-1,p=n
:repeat
set /a p-=1
if %p% lss 0 goto array
for /l %%a in (1 1 %m%) do (
setlocal enabledelayedexpansion
if !t! gtr %n% set /a t=1
if !i! gtr %n% set /a i=1
set /a s=!t!+1,q=!i!+1
if !s! gtr %n% set /a s=1
if !q! gtr %n% set /a q=1
set /a a!s!_!q!=a!t!_!i!+1,t+=1,i+=1
set /a temp+=1
if !temp! equ %n% (
set /a temp=1,tmp=a!s!_!q!,q-=1,i-=1
if !q! equ 0 set /a q=n
set /a a!s!_!q!=tmp+1
goto repeat
)
)
pause
:array
echo Now behold the powerful Magic Sqaure^^!:
set /a a!t!_!n!=1
for /l %%c in (!n! -1 1) do (
for /l %%d in (1 1 !n!) do (
set /a result=a%%d_%%c
set /p=!result!nul

簡単なプロセス、ディスク、ログ監視用のシェルスクリプト

#!/bin/bas
#
################################################################################
# process status monitor config
################################################################################
# process num
ProcNum=2
#
ProcUser[0]=sybase
ProcName[0]=dataserver
#
ProcUser[1]=sybiq
ProcName[1]=iqsrv15
#
#
################################################################################
# filesystem space monitor config
################################################################################
# filesystem space num
FsNum=1
#
# FsName: filesystem name
# MaxPercent: maximum filesystem space used
FsName[0]=/home/roo/
MaxPercent[0]=90
#
#
################################################################################
# program log monitor config
################################################################################
# LogNum:log num
LogNum=1
#
# LogDir: log file directory
# LogName: log file name
# MaxHoldMin: warning if log file doesn’t increase in appointed minutes
LogDir[0]=/home/roo/
LogName[0]=$(date +%Y%m%d).log
MaxHoldMin[0]=10
#
#
################################################################################
# function declaration
################################################################################
# function get process id
function GetPID #User #Name
{
PsUser=$1
PsName=$2
pid=$(ps -u $PsUser|grep $PsName|grep -v grep|grep -v vi|grep -v dbx \
|grep -v tail|grep -v start|grep -v stop |sed -n 1p |awk ‘{print $1}’)
echo $pid
}
#
# function get filesystem space
function GetDiskSpc #FileSystem
{
if [ $# -ne 1 ]; then
return 1
fi
#
FsDir=$1
DiskSpace=$(df -P $FsDir |tail -1 |awk ‘{print $5}’ |awk -F% ‘{print $1}’)
echo $DiskSpace
}
#
#
function GetLogHold #LogPath
{
LogTime=$(ls –full-time $LogPath | awk ‘{print $6″ “$7}’ | cut -d”.” -f1)
SYSTime=$(date +%F” “%T)
echo | \
awk -v T1=LogTime -v T2=SYSTime ‘{
t1=mktime(T1);
t2=mktime(T2);
dif=(t2-t1)/60;
print dif}’
}
#
################################################################################
# process check
################################################################################
echo
echo “– PROCESS STATUS CHECK BEGIN.”
i=0
while [ $i -lt $ProcNum ]
do
echo -n “Check process ${ProcName[$i]}: ”
PID=$(GetPID ${ProcUser[$i]} ${ProcName[$i]})
#
if [ “-$PID” == “-” ]; then
echo “Warning: process ${ProcName[$i]} does not exist!”
else
echo “Process ${ProcName[i]} is normal.”
fi
#
echo
i=$[ $i + 1 ]
done
#
echo “– PROCESS STATUS CHECK END.”
echo
echo
#
################################################################################
# file system spaces check
################################################################################
echo
echo “– FILESYSTEM SPACE CHECK BEGIN.”
i=0
while [ $i -lt $FsNum ]
do
echo -n “Check filesystem ${FsName[$i]}: ”
DiskSpace=$(GetDiskSpc ${FsName[$i]})
#
if [ $DiskSpace -gt ${MaxPercent[$i]} ]; then
echo “Warning: filesystem (${FsName[$i]}) used $DiskSpace% more than ${MaxPercent[$i]}%!”
else
echo “Filesystem [${FsName[$i]}] used $DiskSpace%.”
fi
#
echo
i=$[ $i + 1 ]
done
#
echo “– FILESYSTEM SPACE CHECK END.”
echo
echo
#
################################################################################
# program log check
################################################################################
echo
echo “– LOG STATUS CHECK BEGIN.”
i=0
while [ $i -lt $LogNum ]
do
echo -n “Check log ${LogDir[i]}${LogName[i]} : ”
LogHoldMin=$(GetLogHold ${LogDir[i]}${LogName[i]})
#
if [ $LogHoldMin -gt ${MaxHoldMin[0]} ]; then
echo “Warning: log [${LogDir[i]}${LogName[i]}] hold $LogHoldMin minutes more than ${MaxHoldMin[0]}!”
else
echo “Log [${LogDir[i]}${LogName[i]}] hold $LogHoldMin minutes.”
fi
#
echo
i=$[ $i + 1 ]
done
#
echo “– LOG STATUS CHECK END.”
echo
echo
#

batファイルは直接あるドライブのディレクトリに入る

@echo off
cd\
e:
cd Python33
dir
CMD

oracleオンラインのユーザーを殺す

oracleありかのサーバーの上でrootユーザーを使ってこのシナリオを実行する
$1:当oracleのユーザです

#!/bin/sh

function _oracleplus(){
su – oracle -c “$oraclehome/bin/sqlplus /nolog” < onlinesession.dmp
echo “start kill $1 session!!!”
cat onlinesession.dmp | while read line;
do
_oracleplus “$line”
done
echo “end kill $1 session!!!”

CSSの一行の省略

<p style=”width: 300px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;”> 省略してください! 省略してください! </p>

syslog client 大量発送テキストをテストする

コードをsyslog_client.pyとして保存して、cmd.txtと同じデイlレクトリに入れる。
コマンド:python syslog_client.py -f cmd.txt -h 1.1.1.1
cmd.txtはログ内容ファイル、1.1.1.1はログサーバーのIPアドレスです。

import socket
import sys
importfile = sys.argv[2]
ipaddr = sys.argv[4]
f = file(importfile,’r’)
address = (ipaddr,514)
level = 2
facility = 2
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while True:
line = f.readline().strip()
if len(line) == 0:
break
msg = ‘<%d> %s’ % (level+facility,line)
s.sendto(msg, address)
f.close()
s.close()

メール校正の正規表現

function isEmail($email) {
return strlen($email) > 6 && preg_match(“/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/”, $email);
}

PHPソースコード:list使用タグ

<?php
$result = mysql_query(“SELECT id, name, salary FROM employees”, $conn);
while (list($id, $name, $salary) = mysql_fetch_row($result)) {
echo ” <tr>\n” .
” <td><a href=\”info.php?id=$id\”>$name</a></td>\n” .
” <td>$salary</td>\n” .
” </tr>\n”;
}
?>