½ºÅ©¸³Æ® µ¿ÀÛÀÌ ÀÌ»óÇØ¿ä..µµ¿òÁÖ¼¼¿ä

   Á¶È¸ 6294   Ãßõ 0    

쏠라리스 서버인데...로그가 쌓이는 폴더내 daemon.log라는 화일에서
 
KST(한국표준시)기준으로 오늘날짜 로그, 어제날짜 로그, 엊그제 날짜 로그를 뽑아서
 
하나로 합치는 스크립트입니다.
 
스크립트 내용에서 골자부분인 이하 각각의 라인을
 
cat /nsr/logs/daemon.log | grep `TZ=KST+15;date +%m"/"%d"/"%y` | grep done
 
cat /nsr/logs/daemon.log | grep `TZ=KST+39;date +%m"/"%d"/"%y` | grep done
 
cat /nsr/logs/daemon.log | grep `TZ=KST-9;date +%m"/"%d"/"%y`  | grep done
 
 
프람프트(#)상에서 각각 실행시키면 첨부된 내용처럼 원하는 날짜에 만들어진 로그를 가지고 옵니다.
 
 
그런데 저 명령들을 하나의 화일(스크립트화일)로 만들어서 하면 오늘날짜데이타를 세번 반복해서 만드는 이상한 결과가 나옵니다.
 
 
이하 첨부에 적은 내용처럼 위 각각 라인의 명령을 하나의 스크립트화일(lto1_satur_mon.sh)로 묶어서
 
 
 
damoabk:/nsr/logs]cat lto1_satur_mon.sh
#!/bin/sh
#
 
## 기존로그화일삭제
rm /nsr/logs/daily_backup_check_log/*.txt
 
## 엊그제날짜 로그데이타 수집 후 ,  /nsr/logs/daily_backup_check_log/lto1_result_saturday.txt 에 넣기
cat /nsr/logs/daemon.log | grep `TZ=KST+15;date +%m"/"%d"/"%y` | grep done > /nsr/logs/daily_backup_check_log/lto1_result_saturday.txt

## 어제날짜 로그데이타 수집 후 ,  /nsr/logs/daily_backup_check_log/lto1_result_saturday.txt 에 넣기
cat /nsr/logs/daemon.log | grep `TZ=KST+39;date +%m"/"%d"/"%y` | grep done > /nsr/logs/daily_backup_check_log/lto1_result_sunday.txt
## 오늘날짜 로그데이타 수집 후 ,  /nsr/logs/daily_backup_check_log/lto1_result_monday.txt 에 넣기
cat /nsr/logs/daemon.log | grep `TZ=KST-9;date +%m"/"%d"/"%y`  | grep done >  /nsr/logs/daily_backup_check_log/lto1_result_monday.txt
 
 
## 화일하나로 합치기
ls  /nsr/logs/daily_backup_check_log/*.txt |sort -r|xargs cat > /nsr/logs/daily_backup_check_log/lto1_result_`date +%Y%m%d`.txt
 
## 화일합치고 난 후 소스데이타화일 삭제
rm  /nsr/logs/daily_backup_check_log/lto1_result_saturday.txt lto1_result_sunday.txt lto1_result_monday.txt
 
 
 
실행을 시키면 다음과 같이 오늘날짜(24일)것만 세번 반복해서 만들어지는데...이런 황당한 경우가 ...
 
어떻게 해야 해결할 수 있을까요?  뭐가 문제인가요?
 
  • 02/24/14 03:00:46 nsrd: damoaap:I:\Event_Security_Log_Backup done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:01:09 nsrd: damoaap:I:\fromC-Jeus33-logs done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:01:22 nsrd: damoaap:I:\webtob done saving to pool 'FDATA' (FDATA.159) 112 KB
    02/24/14 03:01:37 nsrd: damoaap:C:\Jeus33 done saving to pool 'FDATA' (FDATA.159) 9339 KB
    02/24/14 03:01:56 nsrd: damoaap:C:\BMS done saving to pool 'FDATA' (FDATA.159) 1668 KB
    02/24/14 03:04:16 nsrd: damoaap:G:\g-file done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:04:51 nsrd: damoaap:C:\GW done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:06:20 nsrd: damoaap2:C:\uniERPII done saving to pool 'FDATA' (FDATA.159) 301 MB
    02/24/14 03:07:44 nsrd: damoaap:G:\file done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:07:49 nsrd: damoabk:index:damoaap done saving to pool 'FDATA' (FDATA.159) 50 KB
    02/24/14 03:17:53 nsrd: damoaap2:E:\ done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:17:57 nsrd: damoabk:index:damoaap2 done saving to pool 'FDATA' (FDATA.159) 253 KB
    02/24/14 06:00:36 nsrd: damoabk:/nsr done saving to pool 'FDATA' (FDATA.159) 96 MB
    02/24/14 06:00:40 nsrd: damoabk:index:damoabk done saving to pool 'FDATA' (FDATA.159) 68 KB
    02/24/14 06:00:44 nsrd: damoabk:bootstrap done saving to pool 'FDATA' (FDATA.159) 2871 KB
  • 02/24/14 03:00:46 nsrd: damoaap:I:\Event_Security_Log_Backup done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:01:09 nsrd: damoaap:I:\fromC-Jeus33-logs done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:01:22 nsrd: damoaap:I:\webtob done saving to pool 'FDATA' (FDATA.159) 112 KB
    02/24/14 03:01:37 nsrd: damoaap:C:\Jeus33 done saving to pool 'FDATA' (FDATA.159) 9339 KB
    02/24/14 03:01:56 nsrd: damoaap:C:\BMS done saving to pool 'FDATA' (FDATA.159) 1668 KB
    02/24/14 03:04:16 nsrd: damoaap:G:\g-file done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:04:51 nsrd: damoaap:C:\GW done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:06:20 nsrd: damoaap2:C:\uniERPII done saving to pool 'FDATA' (FDATA.159) 301 MB
    02/24/14 03:07:44 nsrd: damoaap:G:\file done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:07:49 nsrd: damoabk:index:damoaap done saving to pool 'FDATA' (FDATA.159) 50 KB
    02/24/14 03:17:53 nsrd: damoaap2:E:\ done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:17:57 nsrd: damoabk:index:damoaap2 done saving to pool 'FDATA' (FDATA.159) 253 KB
    02/24/14 06:00:36 nsrd: damoabk:/nsr done saving to pool 'FDATA' (FDATA.159) 96 MB
    02/24/14 06:00:40 nsrd: damoabk:index:damoabk done saving to pool 'FDATA' (FDATA.159) 68 KB
    02/24/14 06:00:44 nsrd: damoabk:bootstrap done saving to pool 'FDATA' (FDATA.159) 2871 KB
  • 02/24/14 03:00:46 nsrd: damoaap:I:\Event_Security_Log_Backup done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:01:09 nsrd: damoaap:I:\fromC-Jeus33-logs done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:01:22 nsrd: damoaap:I:\webtob done saving to pool 'FDATA' (FDATA.159) 112 KB
    02/24/14 03:01:37 nsrd: damoaap:C:\Jeus33 done saving to pool 'FDATA' (FDATA.159) 9339 KB
    02/24/14 03:01:56 nsrd: damoaap:C:\BMS done saving to pool 'FDATA' (FDATA.159) 1668 KB
    02/24/14 03:04:16 nsrd: damoaap:G:\g-file done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:04:51 nsrd: damoaap:C:\GW done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:06:20 nsrd: damoaap2:C:\uniERPII done saving to pool 'FDATA' (FDATA.159) 301 MB
    02/24/14 03:07:44 nsrd: damoaap:G:\file done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:07:49 nsrd: damoabk:index:damoaap done saving to pool 'FDATA' (FDATA.159) 50 KB
    02/24/14 03:17:53 nsrd: damoaap2:E:\ done saving to pool 'FDATA' (FDATA.159)
    02/24/14 03:17:57 nsrd: damoabk:index:damoaap2 done saving to pool 'FDATA' (FDATA.159) 253 KB
    02/24/14 06:00:36 nsrd: damoabk:/nsr done saving to pool 'FDATA' (FDATA.159) 96 MB
    02/24/14 06:00:40 nsrd: damoabk:index:damoabk done saving to pool 'FDATA' (FDATA.159) 68 KB
    02/24/14 06:00:44 nsrd: damoabk:bootstrap done saving to pool 'FDATA' (FDATA.159) 2871 KB
 
 
 
 
 
 
 
 
 
 
--- 첨부내용 -----
 
스크립트화 하지 않고 #상에서 각각 명령을 실행시켜서 결과를 얻는 모습

[damoabk:/nsr/logs]cat /nsr/logs/daemon.log | grep `TZ=KST+15;date +%m"/"%d"/"%y` | grep done -- 어제꺼
02/23/14 03:01:43 nsrd: damoaap:I:\Event_Security_Log_Backup done saving to pool 'FDATA' (FDATA.159)
02/23/14 03:02:05 nsrd: damoaap:I:\fromC-Jeus33-logs done saving to pool 'FDATA' (FDATA.159)
02/23/14 03:02:19 nsrd: damoaap:I:\webtob done saving to pool 'FDATA' (FDATA.159) 61 KB
02/23/14 03:02:34 nsrd: damoaap:C:\Jeus33 done saving to pool 'FDATA' (FDATA.159) 9148 KB
02/23/14 03:02:58 nsrd: damoaap:C:\BMS done saving to pool 'FDATA' (FDATA.159) 1667 KB
02/23/14 03:05:16 nsrd: damoaap:G:\g-file done saving to pool 'FDATA' (FDATA.159)
02/23/14 03:05:48 nsrd: damoaap:C:\GW done saving to pool 'FDATA' (FDATA.159)
02/23/14 03:07:32 nsrd: damoaap2:C:\uniERPII done saving to pool 'FDATA' (FDATA.159) 300 MB
02/23/14 03:08:29 nsrd: damoaap:G:\file done saving to pool 'FDATA' (FDATA.159)
02/23/14 03:08:33 nsrd: damoabk:index:damoaap done saving to pool 'FDATA' (FDATA.159) 27 KB
02/23/14 03:19:06 nsrd: damoaap2:E:\ done saving to pool 'FDATA' (FDATA.159)
02/23/14 03:19:10 nsrd: damoabk:index:damoaap2 done saving to pool 'FDATA' (FDATA.159) 127 KB
02/23/14 06:03:15 nsrd: damoabk:/nsr done saving to pool 'FDATA' (FDATA.159) 3655 MB
02/23/14 06:03:18 nsrd: damoabk:index:damoabk done saving to pool 'FDATA' (FDATA.159) 2668 KB
02/23/14 06:03:22 nsrd: damoabk:bootstrap done saving to pool 'FDATA' (FDATA.159) 2863 KB
02/23/14 20:00:31 nsrd: ones:/ done saving to pool 'FDATA' (FDATA.159) 10 MB
02/23/14 20:00:31 nsrd: ones:/usr done saving to pool 'FDATA' (FDATA.159) 5583 KB
02/23/14 20:00:35 nsrd: damoabk:index:ones done saving to pool 'FDATA' (FDATA.159) 297 KB
02/23/14 20:01:05 nsrd: damoabk:index:credi2 done saving to pool 'FDATA' (FDATA.159)
02/23/14 21:00:19 nsrd: ekp-exchange:D:\NIAEKP done saving to pool 'FDATA' (FDATA.159)
02/23/14 21:00:19 nsrd: ekp-exchange:D:\KAONI_TEMPORARY done saving to pool 'FDATA' (FDATA.159) 379 KB
02/23/14 21:00:21 nsrd: ekp-search:E:\j2sdk1.4.2_04 done saving to pool 'FDATA' (FDATA.159)
02/23/14 21:00:22 nsrd: damoabk:index:ekp-exchange done saving to pool 'FDATA' (FDATA.159) 41 KB
02/23/14 21:11:16 nsrd: ekp-search:E:\sf-1 done saving to pool 'FDATA' (FDATA.159) 5416 MB
02/23/14 21:11:19 nsrd: damoabk:index:ekp-search done saving to pool 'FDATA' (FDATA.159) 356 KB
02/23/14 22:00:28 nsrd: damoabk:index:ekp-web done saving to pool 'FDATA' (FDATA.159)
 
[damoabk:/nsr/logs]cat /nsr/logs/daemon.log | grep `TZ=KST+39;date +%m"/"%d"/"%y` | grep done  -- 엊그제꺼
02/22/14 03:06:59 nsrd: damoaap:C:\BMS done saving to pool 'FDATA' (FDATA.204) 201 MB
02/22/14 03:07:33 nsrd: damoaap:I:\Event_Security_Log_Backup done saving to pool 'FDATA' (FDATA.204) 988 MB
02/22/14 03:16:46 nsrd: damoaap:C:\Jeus33 done saving to pool 'FDATA' (FDATA.204) 2007 MB
02/22/14 03:23:19 nsrd: damoaap:I:\fromC-Jeus33-logs done saving to pool 'FDATA' (FDATA.204) 2298 MB
02/22/14 03:31:55 nsrd: damoaap:I:\webtob done saving to pool 'FDATA' (FDATA.204) 2347 MB
02/22/14 03:40:25 nsrd: damoaap:C:\GW done saving to pool 'FDATA' (FDATA.204) 1928 MB
02/22/14 03:51:53 nsrd: damoaap2:C:\uniERPII done saving to pool 'FDATA' (FDATA.204) 2306 MB
02/22/14 06:00:09 nsrd: damoabk:/nsr done saving to pool 'FDATA' (FDATA.157) 106 MB
02/22/14 06:00:11 nsrd: damoabk:index:damoabk done saving to pool 'FDATA' (FDATA.157) 419 KB
02/22/14 06:00:16 nsrd: damoabk:bootstrap done saving to pool 'FDATA' (FDATA.157) 2837 KB
02/22/14 06:16:37 nsrd: damoaap:G:\g-file done saving to pool 'FDATA' (FDATA.157) 35 GB
02/22/14 10:46:40 nsrd: damoaap2:E:\ done saving to pool 'FDATA' (FDATA.159) 95 GB
02/22/14 10:47:07 nsrd: damoabk:index:damoaap2 done saving to pool 'FDATA' (FDATA.159) 504 MB
02/22/14 11:02:42 nsrd: damoaap:G:\file done saving to pool 'FDATA' (FDATA.159) 121 GB
02/22/14 11:02:57 nsrd: damoabk:index:damoaap done saving to pool 'FDATA' (FDATA.159) 237 MB
02/22/14 20:02:08 nsrd: damoabk:index:credi2 done saving to pool 'FDATA' (FDATA.159)
02/22/14 20:02:15 nsrd: ones:/ done saving to pool 'FDATA' (FDATA.159) 8453 KB
02/22/14 20:02:42 nsrd: ones:/usr done saving to pool 'FDATA' (FDATA.159) 4679 KB
02/22/14 20:02:45 nsrd: damoabk:index:ones done saving to pool 'FDATA' (FDATA.159) 147 KB
02/22/14 21:00:19 nsrd: ekp-exchange:D:\NIAEKP done saving to pool 'FDATA' (FDATA.159)
02/22/14 21:00:19 nsrd: ekp-exchange:D:\KAONI_TEMPORARY done saving to pool 'FDATA' (FDATA.159) 239 KB
02/22/14 21:00:22 nsrd: ekp-search:E:\j2sdk1.4.2_04 done saving to pool 'FDATA' (FDATA.159)
02/22/14 21:00:22 nsrd: damoabk:index:ekp-exchange done saving to pool 'FDATA' (FDATA.159) 20 KB
02/22/14 21:15:36 nsrd: ekp-search:E:\sf-1 done saving to pool 'FDATA' (FDATA.159) 8273 MB
02/22/14 21:15:39 nsrd: damoabk:index:ekp-search done saving to pool 'FDATA' (FDATA.159) 191 KB
02/22/14 22:01:18 nsrd: damoabk:index:ekp-web done saving to pool 'FDATA' (FDATA.159)
 
[damoabk:/nsr/logs]cat /nsr/logs/daemon.log | grep `TZ=KST-9;date +%m"/"%d"/"%y`  | grep done  -- 오늘꺼
02/24/14 03:00:46 nsrd: damoaap:I:\Event_Security_Log_Backup done saving to pool 'FDATA' (FDATA.159)
02/24/14 03:01:09 nsrd: damoaap:I:\fromC-Jeus33-logs done saving to pool 'FDATA' (FDATA.159)
02/24/14 03:01:22 nsrd: damoaap:I:\webtob done saving to pool 'FDATA' (FDATA.159) 112 KB
02/24/14 03:01:37 nsrd: damoaap:C:\Jeus33 done saving to pool 'FDATA' (FDATA.159) 9339 KB
02/24/14 03:01:56 nsrd: damoaap:C:\BMS done saving to pool 'FDATA' (FDATA.159) 1668 KB
02/24/14 03:04:16 nsrd: damoaap:G:\g-file done saving to pool 'FDATA' (FDATA.159)
02/24/14 03:04:51 nsrd: damoaap:C:\GW done saving to pool 'FDATA' (FDATA.159)
02/24/14 03:06:20 nsrd: damoaap2:C:\uniERPII done saving to pool 'FDATA' (FDATA.159) 301 MB
02/24/14 03:07:44 nsrd: damoaap:G:\file done saving to pool 'FDATA' (FDATA.159)
02/24/14 03:07:49 nsrd: damoabk:index:damoaap done saving to pool 'FDATA' (FDATA.159) 50 KB
02/24/14 03:17:53 nsrd: damoaap2:E:\ done saving to pool 'FDATA' (FDATA.159)
02/24/14 03:17:57 nsrd: damoabk:index:damoaap2 done saving to pool 'FDATA' (FDATA.159) 253 KB
02/24/14 06:00:36 nsrd: damoabk:/nsr done saving to pool 'FDATA' (FDATA.159) 96 MB
02/24/14 06:00:40 nsrd: damoabk:index:damoabk done saving to pool 'FDATA' (FDATA.159) 68 KB
02/24/14 06:00:44 nsrd: damoabk:bootstrap done saving to pool 'FDATA' (FDATA.159) 2871 KB
[damoabk:/nsr/logs]
ªÀº±Û Àϼö·Ï ½ÅÁßÇÏ°Ô.
¸®´ª½º ȯ°æ¿¡¼­ Çغ¸´Ï TZȯ°æº¯¼ö°¡ Á¦´ë·Î ¼ÂÆÃÀÌ ¾ÈµÇ¼­ Å×½ºÆ®´Â ¸øÇغñ¸¿ä.
¼Ö¶ó¸®½ºÀÇ date ¸í·É¾î¿¡¼­ -d ¿É¼ÇÀ» Á¦´ë·Î Áö¿øÇÑ´Ù¸é ¾Æ·¡ ¸í·É¾î·Î ¿øÇÏ´Â °á°ú°¡ »ÌÀ» ¼ö ÀÖ½À´Ï´Ù.

cat /nsr/logs/daemon.log | grep $(date +'%m/%d/%y' -d 'TZ="Asia/Seoul" 15hour') | grep done
cat /nsr/logs/daemon.log | grep $(date +'%m/%d/%y' -d 'TZ="Asia/Seoul" 39hour') | grep done
cat /nsr/logs/daemon.log | grep $(date +'%m/%d/%y' -d 'TZ="Asia/Seoul" -9hour') | grep done


QnA
Á¦¸ñPage 3888/5692
2015-12   1552972   ¹é¸Þ°¡
2014-05   5017564   Á¤ÀºÁØ1
2015-12   6291   2CPUÃÖÁÖÈñ
2017-09   6292   Smile
2008-09   6292   Çѵ¿ÈÆ
2013-07   6292   Ç®·Îµå½Ã½ºÅÛ
2012-01   6292   ÀÌ»óÇå
2005-06   6292   ¹ÚÁ¤Èñ
2010-11   6292   °­»óÂù
2016-12   6293   1CPUÁöâÈÆ
2008-01   6293   ±è¼±ÅÂ
2005-03   6293   À¯¿ë¼ö
2013-04   6293   Æĸ®´ë¿Õ
2010-10   6293   stone92±è°æ¹Î
2015-10   6293   ±ÙÀ°Åë
2016-07   6294   Á¤Áøȯ
2014-04   6294   ÀÎÃʸ®
2014-12   6294   ¹èÁؼ®
2017-04   6294   Ç϶ôÀå¼öÀÍ
2008-12   6294   ±è°Ç¿ì
2016-03   6294   ¹Ú
2018-05   6294   ȣȣ