페이지

2014년 5월 28일 수요일

[linux] 5분단위 파일만들기

#d=date +'%Y%m%d%H%M'
#insDate=`date --date='' '+%Y%m%d%H%M'`
insDate=`date '+%Y%m%d%H%M'`
insDateForDir=`date '+%Y%m%d'`

#echo ${insDate:10:3} 
strForMinute=${insDate:11:1}
echo "분단위 마지막 한 자리=> "  ${strForMinute}

lastDate=${insDate:0:11}
echo "11번째자리가지 자른 날자=>" ${lastDate}

fileNameForLstMinute=0


case "${strForMinute}" in
0)
        fileNameForLstMinute=0
        ;;
1)
        fileNameForLstMinute=0
        ;;
2)
        fileNameForLstMinute=0
        ;;
3)
        fileNameForLstMinute=0
        ;;
4)
        fileNameForLstMinute=0
        ;;
5)
        fileNameForLstMinute=5
        ;;
6)
        fileNameForLstMinute=5
        ;;
7)
        fileNameForLstMinute=5
        ;;
8)
        fileNameForLstMinute=5
        ;;
9)
        fileNameForLstMinute=5
        ;;
*)      echo "there is no value"
        ;;
esac

echo "가공된 분자리 =>" ${fileNameForLstMinute} 

lastDate=${lastDate}${fileNameForLstMinute}

echo "최종날자=>" ${lastDate}

serverNum="001"
serviceGubn="service"

#ohp
logDir="/logs/test/"${serviceGubn}"/"${insDateForDir}"/"                                                       
logFile="OHP."${serverNum}"."${lastDate}".log"                                                                    
logOhp=${logDir}${logFile}                                                                                        
mkdir -p -- "${logDir%/*}" && touch  ${logOhp}                                                                    
                                                                                                                  
echo ${logOhp} 

[postgresql] execute function in shell using crontab

1. register the account information

vi ~/.pgpass
localhost:portnumber:db_name:username:password

2. create shell script

vi shell.sh

#!/bin/sh

dbname="dbname"
username="username"

/opt/postgres/9.3/bin/psql $dbname $username<<EOF
select function_name();
EOF


3. register into the crontab

*/1 * * * * /home/shell/shell.sh > /log/errlog.log 2>&1

[altibase]execute altibase procedure every 1 minute using crontab

export ALTIBASE_HOME='/altibase/altibase_home'
export PATH=./:$PATH
ISQL="/altibase/altibase_home/bin/isql -s localhost -u user-p pass-port 20300"

${ISQL} << EOF
        exec PROC_NAME;
        quit
EOF

[linux] here-document at line 10 delimited by end-of-file (wanted `EOF')

remove any character before and after "EOF"

meaning remove all tabs, whitespaces, special characters etc. before and after the EOF,

[linux] when crontab does not working


  1. use absolute path
  2. check error message using following script
    1. */1 * * * * /test/test.sh > /tmp/test.log 2>&1
  3. set environmet variable in the script file





2014년 5월 26일 월요일

[altibase]using bind variable


[altibase]create partition table


  • CREATE TABLE

CREATE TABLE TESTADM.TB_TEST_PART
(
    SEQ NUMBER(13) NOT NULL,
    NAME VARCHAR(20),
    AGE VARCHAR(20),
    --PARTITION_ID SMALLINT DEFAULT MOD(DATEDIFF(TO_DATE('20140501','YYYYMMDD'),SYSDATE,'MONTH'),60) NOT NULL
    PARTITION_ID SMALLINT DEFAULT MOD(DATEDIFF(TO_DATE('20140525','YYYYMMDD'),SYSDATE,'DAY'),14)  NOT NULL
)
PARTITION BY RANGE (PARTITION_ID)
(
    PARTITION P_00 VALUES LESS THAN  ( 1 ),
    PARTITION P_01 VALUES LESS THAN  ( 2 ),
    PARTITION P_02 VALUES LESS THAN  ( 3 ),
    PARTITION P_03 VALUES LESS THAN  ( 4 ),
    PARTITION P_04 VALUES LESS THAN  ( 5 ),
    PARTITION P_05 VALUES LESS THAN  ( 6 ),
    PARTITION P_06 VALUES LESS THAN  ( 7 ),
    PARTITION P_07 VALUES LESS THAN  ( 8 ),
    PARTITION P_08 VALUES LESS THAN  ( 9 ),
    PARTITION P_09 VALUES LESS THAN  ( 10 ),
    PARTITION P_10 VALUES LESS THAN  ( 11 ),
    PARTITION P_11 VALUES LESS THAN  ( 12 ),
    PARTITION P_12 VALUES LESS THAN  ( 13 ),
    PARTITION P_13 VALUES LESS THAN  ( 14 ),
    PARTITION P_DEF VALUES DEFAULT
)
TABLESPACE TS_TEST_DISK_DAT
;



  • CREATE PK

ALTER TABLE TESTADM.TB_TEST_PART add constraint PK_TB_TEST_PART primary key(PARTITION_ID, SEQ) using index local
(
partition PK_TB_TEST_PART_P_00 on P_00 tablespace TS_TEST_DISK_IDX,
partition PK_TB_TEST_PART_P_01 on P_01 tablespace TS_TEST_DISK_IDX,
partition PK_TB_TEST_PART_P_02 on P_02 tablespace TS_TEST_DISK_IDX,
partition PK_TB_TEST_PART_P_03 on P_03 tablespace TS_TEST_DISK_IDX,
partition PK_TB_TEST_PART_P_04 on P_04 tablespace TS_TEST_DISK_IDX,
partition PK_TB_TEST_PART_P_05 on P_05 tablespace TS_TEST_DISK_IDX,
partition PK_TB_TEST_PART_P_06 on P_06 tablespace TS_TEST_DISK_IDX,
partition PK_TB_TEST_PART_P_07 on P_07 tablespace TS_TEST_DISK_IDX,
partition PK_TB_TEST_PART_P_08 on P_08 tablespace TS_TEST_DISK_IDX,
partition PK_TB_TEST_PART_P_09 on P_09 tablespace TS_TEST_DISK_IDX,
partition PK_TB_TEST_PART_P_10 on P_10 tablespace TS_TEST_DISK_IDX,
partition PK_TB_TEST_PART_P_11 on P_11 tablespace TS_TEST_DISK_IDX,
partition PK_TB_TEST_PART_P_12 on P_DEF tablespace TS_TEST_DISK_IDX
);



  • CREATE SEQUENCE

CREATE SEQUENCE SEQ_TEST
START WITH 1
MINVALUE 1
MAXVALUE 9223372036854775806;



  • INSERT TEST DATA

insert into TB_TEST_PART (seq, name, age)
select seq_test.nextval, 'aa', '33' from dual
CONNECT BY LEVEL <= 100
;


  • RETRIEVE DATE USING SPEC. PARTITION TABLE

SELECT * FROM TB_TEST_PART PARTITION (P_01); -->



  • RETRIEVE DATE USING SPEC PARTITION TABLE WITH WHERE CLAUSE

SELECT * FROM TB_TEST_PART
WHERE PARTITION_ID IN ('1','2')




[linux]how to view the hardware info


  • product info
    • dmidecode  | more



  • count of physical CPU
    • # grep 'physical id' /proc/cpuinfo | sort | uniq | wc -l
  •  count of logica CPU 
    • # grep ^processor /proc/cpuinfo | wc -l


  • count of core
    • # grep 'cpu cores' /proc/cpuinfo



  • meminfo
    • cat /proc/meminfo


  • disk 정보
    • fdisk -l | grep Disk


2014년 5월 21일 수요일

[altibase]table space add


1. add datafile

ALTER TABLESPACE TS_SPI_DISK_IDX
ADD DATAFILE 
'/disk0/disk_idx/Test_dist_idx_04.dbf'
SIZE 4096M
AUTOEXTEND OFF; 



2014년 5월 19일 월요일

[sendmail]메일 발송시 속도 높이기


sendmail에서 폼메일을 통해서 다량의 소식지 등을 발송하는 경우 시간이 굉장히 오래걸리는 모습을 보여준다.
처리속도가 느리니 오래 걸리는 수밖에..



그래서 Mail의 queue의 병렬처리를 이용해 발송속도를 높혀보자.

mqueue 폴더에 자신이 원하는 만큼의 큐 폴더를 생성한다. (아래 내용은 5개까지만 만들었다)

[rubi] / > # cd /var/spool/mqueue/
[rubi] /var/spool/mqueue > # mkdir q1 q2 q3 q4 q5 q6 q7 q8 q9 q10 q11 q12



sendmail.cf 파일 내에 QueueDirectory 값을 아래와 같이 수정 해준다.

[rubi] /var/spool/mqueue > # vi /etc/mail/sendmail.cf

# queue directory

#O QueueDirectory=/var/spool/mqueue

O QueueDirectory=/var/spool/mqueue/q*



설정적용 (재시작)

[rubi] /var/spool/mqueue > # /etc/init.d/sendmail restart





병렬처리의 이점은

하나의 디렉토리 안에 몇 천 ~ 몇 만개의 파일들이 존재할 경우 ext3부터는 상당부분 개선 되었지만,

ext2에서는 어마어마한 부하가 유발 하게 되는데 이를 분산시켜서 인덱싱에서 발생하는 불필요한 로드를 방지할 수 있게 된다.

메일발송 될때도 큐에 들어간 메일들이 처리 될때 병렬처리 되어 보다 빠른 처리속도를 보여준다.

갯수에 대한 제한은 확인되지 않지만, 그렇다고 무한정 늘리는 것만이 능사는 아니다.



출처 - http://blog.rubi.kr/sendmail-%EC%A0%84%EC%86%A1%EC%86%8D%EB%8F%84%EB%A5%BC-%EB%86%92%EC%97%AC%EB%B3%B4%EC%9E%90-multi-queue/







추가사항

smtp 붙을때는 localhost로 붙는다 <- 속도차이 엄청 남
->telnet localhost 25

그러나 다음과 같이 수정하면 원격도 빠르다

vi /etc/resolv.conf에서 네임서버 없애기



sendmail.cf에서 수정사항

다음과 같이 수정
O DeliveryMode=defer
O Timeout.queuereturn=1h
O QueueLA=256
O RefuseLA=256
O MaxDaemonChildren=64

DSlocalhost -> DS
O Timeout.ident=0s

다음과 같은 데몬 생성
vi demon
/usr/sbin/sendmail -bd -ODeliveryMode=defer






vi queue1
/usr/sbin/sendmail -q10s -OQueueDirectory=/var/spool/mqueue/q1 -OMaxDaemonChildren=32 \
-OTimeout.initial=30s -OTimeout.connect=30s -OTimeout.iconnect=30s -OTimeout.helo=30s \
-OTimeout.mail=30s


/usr/sbin/sendmail -q30s -OQueueDirectory=/var/spool/mqueue/q1 -OMaxDaemonChildren=4


vi queue2
/usr/sbin/sendmail -q10s -OQueueDirectory=/var/spool/mqueue/q2 -OMaxDaemonChildren=16 \
-OTimeout.initial=30s -OTimeout.connect=30s -OTimeout.iconnect=30s -OTimeout.helo=30s \
-OTimeout.mail=30s

/usr/sbin/sendmail -q30s -OQueueDirectory=/var/spool/mqueue/q2 -OMaxDaemonChildren=4

~

vi queue3
/usr/sbin/sendmail -q10s -OQueueDirectory=/var/spool/mqueue/q3 -OMaxDaemonChildren=16 \
-OTimeout.initial=30s -OTimeout.connect=30s -OTimeout.iconnect=30s -OTimeout.helo=30s \
-OTimeout.mail=30s

/usr/sbin/sendmail -q30s -OQueueDirectory=/var/spool/mqueue/q3 -OMaxDaemonChildren=4


vi queue4
/usr/sbin/sendmail -q10s -OQueueDirectory=/var/spool/mqueue/q4 -OMaxDaemonChildren=16 \
-OTimeout.initial=30s -OTimeout.connect=30s -OTimeout.iconnect=30s -OTimeout.helo=30s \
-OTimeout.mail=30s

/usr/sbin/sendmail -q30s -OQueueDirectory=/var/spool/mqueue/q4 -OMaxDaemonChildren=4

vi queue5
/usr/sbin/sendmail -q10s -OQueueDirectory=/var/spool/mqueue/q5 -OMaxDaemonChildren=16 \
-OTimeout.initial=30s -OTimeout.connect=30s -OTimeout.iconnect=30s -OTimeout.helo=30s \
-OTimeout.mail=30s

/usr/sbin/sendmail -q30s -OQueueDirectory=/var/spool/mqueue/q5 -OMaxDaemonChildren=4


vi queue6
/usr/sbin/sendmail -q10s -OQueueDirectory=/var/spool/mqueue/q6 -OMaxDaemonChildren=16 \
-OTimeout.initial=30s -OTimeout.connect=30s -OTimeout.iconnect=30s -OTimeout.helo=30s \
-OTimeout.mail=30s

/usr/sbin/sendmail -q30s -OQueueDirectory=/var/spool/mqueue/q6 -OMaxDaemonChildren=4



vi queue7
/usr/sbin/sendmail -q10s -OQueueDirectory=/var/spool/mqueue/q7 -OMaxDaemonChildren=16 \
-OTimeout.initial=30s -OTimeout.connect=30s -OTimeout.iconnect=30s -OTimeout.helo=30s \
-OTimeout.mail=30s

/usr/sbin/sendmail -q30s -OQueueDirectory=/var/spool/mqueue/q7 -OMaxDaemonChildren=4




vi queue8
/usr/sbin/sendmail -q10s -OQueueDirectory=/var/spool/mqueue/q8 -OMaxDaemonChildren=16 \
-OTimeout.initial=30s -OTimeout.connect=30s -OTimeout.iconnect=30s -OTimeout.helo=30s \
-OTimeout.mail=30s

/usr/sbin/sendmail -q30s -OQueueDirectory=/var/spool/mqueue/q8 -OMaxDaemonChildren=4


vi queue9
/usr/sbin/sendmail -q10s -OQueueDirectory=/var/spool/mqueue/q9 -OMaxDaemonChildren=16 \
-OTimeout.initial=30s -OTimeout.connect=30s -OTimeout.iconnect=30s -OTimeout.helo=30s \
-OTimeout.mail=30s

/usr/sbin/sendmail -q30s -OQueueDirectory=/var/spool/mqueue/q9 -OMaxDaemonChildren=4


vi queue10
/usr/sbin/sendmail -q10s -OQueueDirectory=/var/spool/mqueue/q10 -OMaxDaemonChildren=16 \
-OTimeout.initial=30s -OTimeout.connect=30s -OTimeout.iconnect=30s -OTimeout.helo=30s \
-OTimeout.mail=30s

/usr/sbin/sendmail -q30s -OQueueDirectory=/var/spool/mqueue/q10 -OMaxDaemonChildren=4


vi queue11
/usr/sbin/sendmail -q10s -OQueueDirectory=/var/spool/mqueue/q11 -OMaxDaemonChildren=16 \
-OTimeout.initial=30s -OTimeout.connect=30s -OTimeout.iconnect=30s -OTimeout.helo=30s \
-OTimeout.mail=30s

/usr/sbin/sendmail -q30s -OQueueDirectory=/var/spool/mqueue/q11 -OMaxDaemonChildren=4


~


vi queue12
/usr/sbin/sendmail -q10s -OQueueDirectory=/var/spool/mqueue/q12 -OMaxDaemonChildren=16 \
-OTimeout.initial=30s -OTimeout.connect=30s -OTimeout.iconnect=30s -OTimeout.helo=30s \
-OTimeout.mail=30s

/usr/sbin/sendmail -q30s -OQueueDirectory=/var/spool/mqueue/q12 -OMaxDaemonChildren=4





삭제 데몬
*/20 * * * * /agent/shell/pdel

vi pdel
for FILE in /var/spool/mqueue/q*/[dq]f*;
do
      echo -ne \\r"Deleting $FILE... ";
      rm $FILE -f;
      echo -n ok;
done;

echo


다음은 sendmail.mc

define(`SMART_HOST', `localhost')dnl
DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl

m4 /etc/mail/sendmail.mc > /etc/sendmail.cf

2014년 5월 16일 금요일

[linux]logrotate

/tomcat/logs/catalina.out {
 copytruncate
 daily
 rotate 30
 compress
 missingok
 notifempty
 dateext
 create 0664 spiwas spiwas
}



//설정경로
/etc/logrotate.d
vi tomcat

//강제로 실행
# logrotate -f /etc/logrotate.d/tomcat # 로그파일 순환 테스트

//디버깅
logrotate -d /etc/logrotate.d/tomcat

//보낸 내역
/var/lib/logrotate.status

//설정
/etc/logrotate.conf

2014년 5월 14일 수요일

[altibase]character set

--캐릭터 셋 확인
select * from v$nls_parameters

환경 변수
 - ALTIBASE_NLS_USE : 데이터 검색 시, 사용자에게 보여주는 문자 셋


v$nls_parameters
    iSQL> select * from v$nls_parameters;
    SESSION_ID                : 122      
    NLS_USE                   : US7ASCII                 -- 접속 client  캐릭터 셋
    NLS_CHARACTERSET          : MS949       -- DB 캐릭터 셋                                  
    NLS_NCHAR_CHARACTERSET    : UTF8 --DB national 캐릭터셋                                  
    NLS_COMP                  : BINARY
    NLS_NCHAR_CONV_EXCP       : FALSE  
    NLS_NCHAR_LITERAL_REPLACE : FALSE  

2014년 5월 13일 화요일

[linux]kill or logout a user

skill -KILL -u user

or

find the pid using ps -ef grep 'name'  command
and kill all process retlated with user account

image

image