'BSD / Linux'에 해당되는 글 26건
- 2010/06/20 nginx (정리 안됨)
- 2010/06/04 MySQL 문자열 치환
- 2010/04/01 Putty 다운로드 (1)
- 2009/09/21 CentOS 5.3 에서 MySQL 5.1 컴파일 설치. (1)
- 2009/06/06 Apache, MySQL, PostgreSQL, PHP 컴파일 옵션
- 2009/05/01 BIND에서 서브도메인에 - 또는 _ 사용하기
- 2009/03/30 자주 사용하는 UID 정리. (1)
- 2009/03/30 conf파일 주석 제거하고 보기. (1)
- 2009/03/02 .htaccess 가지고 놀기 (2)
- 2009/01/07 date명령 Tip.
nginx (정리 안됨)
BSD / Linux 2010/06/20 16:27
./configure \
--prefix=/opt/nginx \
--sbin-path=/opt/nginx/sbin/nginx \
--conf-path=/opt/nginx/conf/nginx.conf \
--error-log-path=/opt/nginx/logs/error.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/subsys/nginx \
--user=nogody \
--group=nogody \
--http-log-path=/opt/nginx/logs/access.log \
--http-client-body-temp-path=/opt/nginx/client_body_temp \
--http-proxy-temp-path=/opt/nginx/proxy_temp \
--http-fastcgi-temp-path=/opt/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/opt/nginx/uwsgi_temp \
--with-pcre \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_flv_module \
--with-http_ssl_module \
--with-http_dav_module
/opt/spawn-fcgi/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nobody -g nobody -f /opt/php/bin/php-cgi -P /var/run/fastcgi-php.pid -C 10
server {
listen 80;c
server_name opt.umttumt.org www.opt.umttumt.org;
access_log off;
location / {
root /home/umttumt/public_html;
index index.php index.html index.htm;
# to forward www to non-www address
if ($host ~* www\.(.*)) {
set $host_without_www $1;
rewrite ^(.*)$ http://$host_without_www$1 permanent;
}
# I added a some write for the testing purpose
# rewrite ^/vps-provider/([^/]*)/$ /myserviceproviders.php?vps_provider=$1 last;
}
location ~ \.php$ {
limit_req zone=antiddos burst=5 nodelay;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/umttumt/public_html$fastcgi_script_name;
fastcgi_read_timeout 180;
include fastcgi_params;
}
}
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/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"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
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
sleep 1
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
#!/bin/sh
#
# php-cgi - php-fastcgi swaping via spawn-fcgi
#
# chkconfig: - 85 15
# description: Run php-cgi as app server
# processname: php-cgi
# config: /etc/sysconfig/phpfastcgi (defaults RH style)
# pidfile: /var/run/php_cgi.pid
# Note: See how to use this script :
# http://www.cyberciti.biz/faq/rhel-fedora-install-configure-nginx-php5/
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
spawnfcgi="/opt/spawn-fcgi/bin/spawn-fcgi"
php_cgi="/opt/php/bin/php-cgi"
prog=$(basename $php_cgi)
server_ip=127.0.0.1
server_port=9000
server_user=nobody
server_group=nobody
server_childs=5
pidfile="/var/run/spawn-fcgi.pid"
# do not edit, put changes in /etc/sysconfig/phpfastcgi
[ -f /etc/sysconfig/phpfastcgi ] && . /etc/sysconfig/phpfastcgi
start() {
[ -x $php_cgi ] || exit 1
[ -x $spawnfcgi ] || exit 2
echo -n $"Starting $prog: "
daemon $spawnfcgi -a ${server_ip} -p ${server_port} -u ${server_user} -g ${server_group} -P ${pidfile} -C ${server_childs} -f ${php_cgi}
retval=$?
echo
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} $prog -QUIT
retval=$?
echo
[ -f ${pidfile} ] && /bin/rm -f ${pidfile}
return $retval
}
restart(){
stop
sleep 2
start
}
rh_status(){
status -p ${pidfile} $prog
}
case "$1" in
start)
start;;
stop)
stop;;
restart)
restart;;
status)
rh_status;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 3
esac
MySQL 문자열 치환
BSD / Linux 2010/06/04 15:46
회원가입할떄 메일주소 잘못 입력한 회원들 메일 주소 수정.
UPDATE `cs_member` SET email = REPLACE( email, '@hanmail.com', '@hanmail.net' ) ;
Putty 다운로드
BSD / Linux 2010/04/01 14:09
CentOS 5.3 에서 MySQL 5.1 컴파일 설치.
BSD / Linux 2009/09/21 14:04
1. 사용자 및 그룹 추가
5. mysql 기본 데이터베이스 생성
수고 하셨습니다.
# groupadd -g 27 mysql2. 최적화 컴파일을 위한 준비작업
# useradd -M -c "MySQL Server" -g mysql -s /bin/false -u 27 -d /opt/mysql mysql
# CFLAGS="-O3 -mpentiumpro -mstack-align-double"3. configure
# CXX=gcc
# CXXFLAGS="-O3 -mpentiumpro -mstack-align-double -felide-constructors -fno-exceptions -fno-rtti"
# ./configure \4. make && make install
--prefix=/opt/mysql \
--localstatedir=/opt/mysql/data \
--with-unix-socket-path=/tmp/mysql.sock \
--sysconfdir=/etc \
--with-mysqld-user=mysql \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static \
--without-debug \
--enable-assembler \
--with-gnu-ld \
--with-big-tables \
--with-plugins=innobase \
--with-charset=euckr \
--with-collation=euckr_korean_ci \
--with-extra-charsets=all
# make && make install $$ echo $?만약 여기서 결과가 0으로 안나오면 망한거니깐 뭐가 잘못됐는지 확인하고 처음부터 다시.
5. mysql 기본 데이터베이스 생성
# cd /opt/mysql/bin/6. 기본 설정파일 복사 및 init 스크립트 복사.
# ./mysql_install_db
# cd /opt/mysql/share/mysql/7. 시작 프로그램 등록
# cp -p my-medium.cnf /etc/my.cnf
# cp -p mysql.server /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld8. 공유 라이브러리 등록
# chkconfig --level 345 mysqld on
# cd /opt/mysql/lib/mysql/9. localstatedir에 mysql 권한 상속
# pwd >> /etc/ld.so.conf
# ldconfig
# chown mysql.mysql -R /opt/mysql/data/10. 서버 시작
# /etc/rc.d/init.d/mysqld start
수고 하셨습니다.
Apache, MySQL, PostgreSQL, PHP 컴파일 옵션
BSD / Linux 2009/06/06 08:25
내가 주로 사용하는 APM 컴파일 옵션.
가급적이면 옵션을 적게(?) 주려고 노력 하고 있지만 마음같지 않다.
./configure --prefix=/opt/mysql \
--localstatedir=/opt/mysql/data \
--with-unix-socket-path=/tmp/mysql.sock \
--sysconfdir=/etc \
--with-mysqld-user=mysql \
--with-big-tables \
--with-plugins=innobase \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static \
--without-debug \
--enable-assembler \
--with-charset=utf8 \
--with-collation=utf8_general_ci \
--with-extra-charsets=all \
--with-gnu-ld
./configure --prefix=/opt/pgsql --with-ldap --with-libxml --with-openssl --with-gnu-ld
./configure --prefix=/opt/httpd \
--enable-modules=so \
--enable-module=shared \
--enable-mods-shared=all \
--enable-so \
--enable-ssl \
--enable-rewrite \
--enable-rule=SHARED_CORE \
--enable-mods-shared=ssl \
--with-ssl \
--with-mpm=prefork
./configure \
--prefix=/opt/php \
--with-apxs2=/opt/httpd/bin/apxs \
--with-config-file-path=/opt/httpd/conf \
--with-mysql=/opt/mysql \
--with-pgsql=/opt/pgsql \
--with-pdo-mysql=/opt/mysql \
--with-pdo-pgsql=/opt/pgsql \
--disable-debug \
--enable-bcmath \
--enable-calendar \
--enable-dbase \
--enable-exif \
--enable-force-cgi-redirect \
--enable-ftp \
--enable-gd-native-ttf \
--enable-magic-quotes \
--enable-mbregex \
--enable-mbstring \
--enable-mod-charset \
--enable-sigchild \
--enable-soap \
--enable-sockets \
--enable-wddx \
--enable-zip \
--with-bz2 \
--with-curl \
--with-freetype-dir=/usr \
--with-gd \
--with-gdbm=/usr \
--with-gettext \
--with-iconv \
--with-imap \
--with-imap-ssl \
--with-jpeg-dir=/usr \
--with-kerberos \
--with-ldap \
--with-libexpat-dir \
--with-libxml-dir \
--with-mcrypt \
--with-openssl \
--without-sqlite \
--with-png-dir=/usr \
--with-snmp \
--with-ttf \
--with-xmlrpc \
--with-zlib \
가급적이면 옵션을 적게(?) 주려고 노력 하고 있지만 마음같지 않다.
./configure --prefix=/opt/mysql \
--localstatedir=/opt/mysql/data \
--with-unix-socket-path=/tmp/mysql.sock \
--sysconfdir=/etc \
--with-mysqld-user=mysql \
--with-big-tables \
--with-plugins=innobase \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static \
--without-debug \
--enable-assembler \
--with-charset=utf8 \
--with-collation=utf8_general_ci \
--with-extra-charsets=all \
--with-gnu-ld
./configure --prefix=/opt/pgsql --with-ldap --with-libxml --with-openssl --with-gnu-ld
./configure --prefix=/opt/httpd \
--enable-modules=so \
--enable-module=shared \
--enable-mods-shared=all \
--enable-so \
--enable-ssl \
--enable-rewrite \
--enable-rule=SHARED_CORE \
--enable-mods-shared=ssl \
--with-ssl \
--with-mpm=prefork
./configure \
--prefix=/opt/php \
--with-apxs2=/opt/httpd/bin/apxs \
--with-config-file-path=/opt/httpd/conf \
--with-mysql=/opt/mysql \
--with-pgsql=/opt/pgsql \
--with-pdo-mysql=/opt/mysql \
--with-pdo-pgsql=/opt/pgsql \
--disable-debug \
--enable-bcmath \
--enable-calendar \
--enable-dbase \
--enable-exif \
--enable-force-cgi-redirect \
--enable-ftp \
--enable-gd-native-ttf \
--enable-magic-quotes \
--enable-mbregex \
--enable-mbstring \
--enable-mod-charset \
--enable-sigchild \
--enable-soap \
--enable-sockets \
--enable-wddx \
--enable-zip \
--with-bz2 \
--with-curl \
--with-freetype-dir=/usr \
--with-gd \
--with-gdbm=/usr \
--with-gettext \
--with-iconv \
--with-imap \
--with-imap-ssl \
--with-jpeg-dir=/usr \
--with-kerberos \
--with-ldap \
--with-libexpat-dir \
--with-libxml-dir \
--with-mcrypt \
--with-openssl \
--without-sqlite \
--with-png-dir=/usr \
--with-snmp \
--with-ttf \
--with-xmlrpc \
--with-zlib \
BIND에서 서브도메인에 - 또는 _ 사용하기
BSD / Linux 2009/05/01 00:59
BIND에서,
서브 도메인에 예를 들어 s_tory.umttumt.org를 사용하려고 하면,
아래와 같은 에러메시지가 발생한다.
처음엔 _ 가 Special character 여서, 별도의 표기법이 존재하는줄 알았다.
낚시글인지 뭔지 모르겠지만, _를 \032로 표시하라고 되어있는곳이 있었는데,
해봐도 안되긴 마찬가지였다.
그래서 찾아본 결과.!
named.conf의 options 지시자세 포함시켜 주면 된다.
예를 들면,
해당 옵션만 추가해주고 나니 아직까지 아무 문제없이 아주 잘된다.
서브 도메인에 예를 들어 s_tory.umttumt.org를 사용하려고 하면,
아래와 같은 에러메시지가 발생한다.
May 1 00:40:22 ns1 named[22521]: master/umttumt.org-zone:95: s_tory.umttumt.org.umttumt.org: bad owner name (check-names)
May 1 00:40:22 ns1 named[22521]: zone umttumt.org/IN: loading master file master/umttumt.org-zone: bad owner name (check-names)
처음엔 _ 가 Special character 여서, 별도의 표기법이 존재하는줄 알았다.
낚시글인지 뭔지 모르겠지만, _를 \032로 표시하라고 되어있는곳이 있었는데,
해봐도 안되긴 마찬가지였다.
그래서 찾아본 결과.!
check-names master ignore;위와 같은 옵션이 존재하는것을 발견했다.
named.conf의 options 지시자세 포함시켜 주면 된다.
예를 들면,
options {이런식으로... 설정 해주면 된다.
version "UNKNOWN";
query-source port 53;
directory "/var/named";
dump-file "data/cache_dump.db";
statistics-file "data/named_stats.txt";
memstatistics-file "data/named_mem_stats.txt";
allow-recursion { trust; };
allow-transfer { none; };
notify no;
check-names master ignore;
};
해당 옵션만 추가해주고 나니 아직까지 아무 문제없이 아주 잘된다.
자주 사용하는 UID 정리.
BSD / Linux 2009/03/30 20:59
postgres:x:26:26:PostgreSQL Server:/usr/local/pgsql:/bin/bash
mysql:x:27:27:MySQL Server:/usr/local/mysql:/bin/false
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
www-data:x:33:33::/home/www-data:/bin/bash
apache:x:48:48:Apache:/var/www:/bin/false
webalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologin
named:x:25:25:Named:/var/named:/sbin/nologin
squid:x:23:23::/var/spool/squid:/sbin/nologin
그냥 500이상 아무거나 줘도 문제 없지만,
결벽증 있는사람들은 이런거 좋아함.
conf파일 주석 제거하고 보기.
BSD / Linux 2009/03/30 20:40
보통 주석이 #으로 시작하는 문서일 경우.
sed '/ *#/d; /^ *$/d' httpd.conf
.htaccess 가지고 놀기
BSD / Linux 2009/03/02 01:32
웹호스팅을 받을 경우,
아파치 설정을 직접 수정할 수 없어 불편한점이 이만저만이 아니다.
이것들을, 완벽하게는 못하지만 어느정도 htaccess를 가지고 해결할 수 있다.
자 그럼 시작.!
들어가기에 앞서, httpd.conf 에서 해당 경로에 Directory 지시자로,
AllowOverride All을 설정해주어야 한다.
AllowOverride가 All 이 아닐경우 몇가지 설정을 변경하는데 제약사항이 있다.
1. 먼저 Application Type 추가 해주기.
AddType application/x-httpd-php .php ..htm .html .shtml .inc .do2. DirectoryIndex 바꿔주기.
DirectoryIndex index.do index.html index.php index.shtml index.htm Default.htm Default.html3. 웹사이트 기본 Charset 바꿔주기.
AddDefaultCharset UTF-8
4. 오류 페이지 바꿔주기
ErrorDocument 400 http://error.umttumt.org/400.html5, ServerSignature 바꾸고, ServerAdmin 메일주소 바꾸기.
ErrorDocument 401 http://error.umttumt.org/401.html
ErrorDocument 403 http://error.umttumt.org/403.html
ErrorDocument 404 http://error.umttumt.org/404.html
ErrorDocument 500 http://error.umttumt.org/500.html
ServerSignature Off6. blog.umttumt.org로 접속했을때, www.umttumt.org/blog를 보여주고 blog.umttumt.org가 실제 주소인것처럼 보이도록 하기.
# 또는 ServerSignature EMail
SetEnv SERVER_ADMIN webmaster@umttumt.org
# 기본은 httpd.conf 에 설정되어있다.
RewriteEngine On7. wiki.umttumt.org로 접속했을때 www.umttumt.org/wiki를 보여주고 wiki.umttumt.org가 실제 주소인것처럼 보이도록 하기.
RewriteBase /
RewriteCond $1 !^(blog)/
RewriteCond %{HTTP_HOST} ^blog\.umttumt\.org [NC]
RewriteRule ^(.*)$ /blog/$1 [L]
RewriteCond $1 !^(wiki)/8. naver.umttumt.org로 접속했을때 www.naver.com으로 완전히 URL을 이동시키기.
RewriteCond %{HTTP_HOST} ^wiki\.umttumt\.org [NC]
RewriteRule ^(.*)$ /wiki/$1 [L]
# 이 설정은 위 6번 에서 RewriteEngine와 RewriteBase를 설정 해줬기 때문에 해당 지시자들을 건너뛴다.
RewriteCond %{http_host} ^naver\.umttumt\.org [NC]9. 실존하지 않는 IP주소로 부터 요청이 왔을때 403 보여주기, 봇 차단하기, 검색엔진을 통한 유입 차단하기.
RewriteRule ^(.*)$ http://www.naver.com/$1 [R=301,NC]
# 이 설정도 위 6번에서 RewriteEngine을 On으로 했기때문에 해당 지시자를 건더 뛴다.
SetEnvIfNoCase remote_addr 10.0 bad_request10. Nimda 웜 차단하기.
SetEnvIfNoCase remote_addr 127.0 bad_request
SetEnvIfNoCase remote_addr 172.16 bad_request
SetEnvIfNoCase remote_addr 172.17 bad_request
SetEnvIfNoCase remote_addr 172.18 bad_request
SetEnvIfNoCase remote_addr 172.19 bad_request
SetEnvIfNoCase remote_addr 172.20 bad_request
SetEnvIfNoCase remote_addr 172.21 bad_request
SetEnvIfNoCase remote_addr 172.22 bad_request
SetEnvIfNoCase remote_addr 172.23 bad_request
SetEnvIfNoCase remote_addr 172.24 bad_request
SetEnvIfNoCase remote_addr 172.25 bad_request
SetEnvIfNoCase remote_addr 172.26 bad_request
SetEnvIfNoCase remote_addr 172.27 bad_request
SetEnvIfNoCase remote_addr 172.28 bad_request
SetEnvIfNoCase remote_addr 172.29 bad_request
SetEnvIfNoCase remote_addr 172.30 bad_request
SetEnvIfNoCase remote_addr 172.31 bad_request
SetEnvIfNoCase remote_addr 192.168 bad_request
SetEnvIfNoCase remote_addr 169.254 bad_request
SetEnvIfNoCase Referer "blog" bad_request
SetEnvIfNoCase Referer "google" bad_request
SetEnvIfNoCase Referer "tistory" bad_request
SetEnvIfNoCase Referer "naver" bad_request
SetEnvIfNoCase Referer "daum" bad_request
SetEnvIfNoCase Referer "yahoo" bad_request
SetEnvIfNoCase User-Agent "Allblog.net RssSync4 (I Love Bluecat)" bad_request
SetEnvIfNoCase User-Agent "MHzXFyder[OPENBLOG]" bad_request
SetEnvIfNoCase User-Agent "UniversalFeedParser" bad_request
SetEnvIfNoCase User-Agent "^Wget" bad_request
SetEnvIfNoCase User-Agent "^Webzip" bad_request
SetEnvIfNoCase User-Agent "^EmailSiphon" bad_request
SetEnvIfNoCase User-Agent "^EmailWolf" bad_request
SetEnvIfNoCase User-Agent "^BPImageWalker" bad_request
Deny from env=bad_request
Redirect /scripts http://error.umttumt.org11. 외부링크 차단하기. (트래픽 감소효과)
Redirect /MSADC http://error.umttumt.org
Redirect /c http://error.umttumt.org
Redirect /d http://error.umttumt.org
Redirect /_mem_bin http://error.umttumt.org
Redirect /msadc http://error.umttumt.org
RedirectMatch (.*)\cmd.exe$ http://error.umttumt.org
SetEnvIFNoCase Referer "umttumt.org" pass
<FilesMatch ".(gif|jpg|png|bmp|zip|tar|rar|alz|a00|ace|jpg|jpeg|txt|GIF|JPG|BMP|ZIP|TAR|RAR|ALZ|A00|ACE|TXT|mp3|MP3|mpeg|MPEG|wav|WAV|asf|ASF|wmv|WMV|swf|SWF|exe|EXE)$">
Order deny,allow
deny from all
allow from env=pass
</FilesMatch>
SetEnvIf Cookie link=ok true
<FilesMatch ".(mid|asf|wma|wmv|mp3|ogg|wav|mpg|mpeg|avi|zip|rar|pdf|exe)$">
Order Deny,Allow
Allow from env=true
Deny from all
</FilesMatch>
이정도?
date명령 Tip.
BSD / Linux 2009/01/07 00:58
date명령은 사실 가장 짜증나고 힘든부분중 하나다.
기본 date 명령으로 현재 시간을 가져올 수는 있지만,
사실상 사용불가능(?) 하다고 보는게 맞다.
date명령의 인자들을 통하여 변형된 현재 시간을 얻어보자.
[umttumt@log1 logs]$ date +%D01/07/09[umttumt@log1 logs]$ date +%Y2009[umttumt@log1 logs]$ date +%m01[umttumt@log1 logs]$ date +%d07[umttumt@log1 logs]$ date +%Y%m%d20090107[umttumt@log1 logs]$ date +%Y-%m-%d2009-01-07[umttumt@log1 logs]$ date +%Y-%m-%d-%H:%M:%S2009-01-07-00:45:42
이런식으로 얻을 수 있다.
사실 date --help나 man date 해보면 금방 얻을 수 있는 정보들이다.
date를 이용하여 조금더 어려운걸 해보자.
현재로부터 1시간전의 시간 얻기.
현재로부터 3일전의 시간 얻기.
현재로부터 3개월 하고 하루 후의 시간 얻기.
[umttumt@log1 logs]$ date2009. 01. 07. (수) 00:48:01 KST[umttumt@log1 logs]$ date --date '1 hour ago'2009. 01. 06. (화) 23:48:06 KST[umttumt@log1 logs]$ date +%Y-%m-%d-%H:%M:%S --date '1 hour ago'2009-01-06-23:48:22[umttumt@log1 logs]$ date2009. 01. 07. (수) 00:48:53 KST[umttumt@log1 logs]$ date --date '3 day ago'2009. 01. 04. (일) 00:49:40 KST[umttumt@log1 logs]$ date --date '3 month'2009. 04. 07. (화) 00:50:00 KST[umttumt@log1 logs]$ date --date '3 month 1 day'2009. 04. 08. (수) 00:50:23 KST
이정도면 원하는 시간을 얻어내고, 해당 시간을 필요한 표형방식대로 가공 가능할 것이다.
현재 시간의 unixtime stamp 얻기.
[umttumt@log1 logs]$ date +%s1231257147
이건 잘 안쓰지만, 혹시 필요할지 모르니 참고로...
이렇게 열심히 설명했지만, 이걸 실제 bash 스크립트에서 변수로 만들지 못하면 사용 불가능할것이다.
변수로 만드는 방법또한 매우 간단하다.
[umttumt@log1 logs]$ TIME=$(date +%y%m%d%H --date '1 hour ago')[umttumt@log1 logs]$ echo $TIME09010623
이런식으로, TIME이라는 변수에 현재부터 1시간 이전의 시간을 담았다.
사실 처음 date를 가지고 이런짓을 하게된 이유는,
윈도우 2008, IIS 웹서버의 로그를 리눅스 서버로 가져와, 리눅스 서버에서 AWStats로 분석하기 위함이었다.
처음 웹서버에서 로그서버로 밀어 넣는 방법을 생각했으나,
역시나 윈도우 서버에서 해결할 방법이 쉽게 보이지 않았다.
결국 생각해낸 방법이, 웹로그를 1시간 단위로 남기고, 해당 로그를 리눅스서버에서 가져오는것이었다.
그런데 문제는, date명령을 통해 충분히 현재 시간을 만들어 낼 수 있었지만,
현재 시간의 로그파일을 가져오면 해당 로그파일은 작성중인 로그이기 때문에 가져와봐요 소용이 없다.
때문에 현재부터 1시간 이전의 로그파일을 가져오기 위해, date명령의 조작으로 원하는 시간값을 얻을 수 있었다.

putty.exe


