stjupiter's blog

script ksh auto clean up log แบบอ่านจาก file config

#!/usr/bin/ksh
OWN_PATH=`pwd`
CFG=${OWN_PATH}/clean_log.cfg
DATA=${OWN_PATH}/temp.tmp
DATA2=${OWN_PATH}/temp2.tmp
DATA3=${OWN_PATH}/temp3.tmp
LISTF=${OWN_PATH}/file.tmp
OVER=${OWN_PATH}/over30days.tmp
CUR_DATE=`date '+%Y%m%d'`
DATE=`date +%d`
echo ===============================================
echo Starting auto cleanup on `date "+%d/%m/%Y %H:%M:%S"`

x=0
lns=`wc -l $CFG`
y=`echo $lns | awk '{print $1}'`
#echo $y $lns
while [ "$x" -lt "$y" ]
  do
     #echo $x $y
     let x=$x+1
     head -n $x ${CFG} | tail -1 > ${DATA}
     SOURCE_PATH=`awk ' BEGIN { FS="|" } { print $1}' ${DATA}`
     STORE_PATH=`awk ' BEGIN { FS="|" } { print $2}' ${DATA}`
     KEEP_DAYS=`awk ' BEGIN { FS="|" } { print $3}' ${DATA}`
     TAR_DAYS=`awk ' BEGIN { FS="|" } { print $4}' ${DATA}`
     KEY=`awk ' BEGIN { FS="|" } { print $5}' ${DATA}`
    
     #echo $SOURCE_PATH
     #echo $STORE_PATH
     #echo $KEEP_DAYS
     #echo $TAR_DAYS
     #echo $KEY

     #TEMP=${KEY}
     #echo $TEMP
     #echo "$SOURCE_PATH -name $KEY \mtime 10"
         
     i=$KEEP_DAYS
     #echo $i $TAR_DAYS
     while [ "$i" -le "$TAR_DAYS" ]
    do
         #echo $i
         find $SOURCE_PATH -name "${KEY}*" -mtime $i > ${LISTF}

Settings for VI (and EX)

Settings for VI (and EX)

You can customize the way VI behaves upon start up. There are several edit options which are available using the :set command, these are the VI and EX editor options available on Wiliki: (You can get this list by typing :set all and then return in command mode)

 

Searching for Text or Characters


,
Repeat the last f, F, t or T command in the reverse direction.
/
Search the file downwards for the string specified after the /.
;
Repeat the last f, F, t or T command.
?
Search the file upwards for the string specified after the ?.
F
Search the current line backwards for the character specified after the 'F' command. If found, move the cursor to the position.
N
Repeat the last search given by '/' or '?', except in the reverse direction.
T
Search the current line backwards for the character specified after the 'T' command, and move to the column after the if it's found.
f
Search the current line for the character specified after the 'f' command. If found, move the cursor to the position.
n
Repeat last search given by '/' or '?'.
t
Search the current line for the character specified after the 't' command, and move to the column before the character if it's found.

EX Commands

The VI editor is built upon another editor, called EX. The EX editor only edits by line. From the VI editor you use the : command to start entering an EX command. This list given here is not complete, but the commands given are the more commonly used. If more than one line is to be modified by certain commands (such as ":s" and ":w" ) the range must be specified before the command. For example, to substitute lines 3 through 15, the command is ":3,15s/from/this/g".

Vi-specific key bindings

Vi-specific key bindings

<!-- copied from Komodo|Help - List Key Bindings for default Vi scheme -->

Vi: Cancel
Ctrl+[
Vi: Close the Current Buffer Without Saving Z, Q
Vi: Cut One Character
x
Vi: Cut One Character to Left
X
Vi: Cut Whole Line and Enter Insert Mode
S
Vi: Cut to End of Line and Enter Insert Mode
C
Vi: Delete the Current Character and Enter Insert Mode
s
Vi: Deletes from cursor to end of line.
D
Vi: Enter Insert Mode
i
Vi: Enter Insert Mode after the Cursor Position
a
Vi: Enter Insert Mode at Start of the Line
I
Vi: Enter Insert mode at the End of the Current Line
A
Vi: Enter command mode
:

ภาษา c Open socket for send message

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

/*void bcopy(char *p1,char *p2,int size)
{
        int j;
        char *tmp1,*tmp2;
        tmp1=p1;
        tmp2=p2;
        for(j=0;j<size;j++) {
                *tmp2++=*tmp1++;
        }
}*/

main(argc, argv)
int argc;
char *argv[];
{
    char pearl[200],localname[20],localIP[20],username[15];
    char filename[40]="";
    char command[100]="";
    char command2[150]="";
    char in[6]="";
    char ServerAddr[25];
    int number;
    int sock;
    FILE *in_file; 
    struct sockaddr_in server,local;
    struct hostent *hp,*hplocal,*gethostbyname();
    gethostname(localname,20);
    hplocal=gethostbyname(localname);
    //bcopy((char *)hplocal->h_addr,(char *)&local.sin_addr,hplocal->h_length);
    local.sin_addr.s_addr = inet_addr(ServerAddr);
    sock = socket(AF_INET, SOCK_STREAM, 0);
    connect(sock, (struct sockaddr*) &local, sizeof(struct sockaddr));
    if (sock < 0) {
        perror("opening stream socket");

ภาษา c Quick Sort function

#include <stdio.h>
//#include <conio.h>

#define max 100

int a[max],n,i,h,l;

main()
{
    void input(void);
    input();
    //getch();
}

void input(void)
    {
        void quicksort(int a[],int l,int h);
        void output(int a[],int n);
        printf("how many:");
        scanf("%d",&n);
        printf("\n");
        printf("Enter the elements:\n");
        for(i=0;i<n;i++)
            {
                scanf("%d",&a[i]);
            }
        l=0;
        h=n-1;
        quicksort(a,l,h);
        printf("sorted array:\n");
        output(a,n);
    }

void quicksort(int a[],int l,int h)
    {
        int temp,key,low,high;
        low=l;
        high=h;
        key=a[(low+high)/2];
        do{
            printf("low=%d,high=%d,key=%d\n",low,high,key);
            while(key>a[low])
                {

ภาษา c Function find previous day หาวันที่ย้อนหลัง (ไว้ใช้กับ UNIX)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

/*============ Substring Function ===================*/

char *substring(size_t start, size_t stop, const char *src, char *dst, size_t size)
{
   int count = stop - start;
   if ( count >= --size )
   {
      count = size;
   }
   sprintf(dst, "%.*s", count, src + start);
   return dst;
}
/*=================== Substring Function ==================*/

/*================== Time diff Function ====================*/
int date_diff(char nowdate[20], int diff)
{
    int i,maxday,nowday,nowmonth,nowyear,prevday,prevmonth,prevyear,monthdiff,diffyear,len;
    long long prevdate;
    char tempnowday[2],tempnowmonth[2],tempnowyear[20],tempprevday[2],tempprevmonth[2],tempprevyear[20],resultday[2],resultmonth[2],resultyear[5],result[20];

//printf("nowdate %s\n",nowdate);

    substring(0,4,nowdate,tempnowyear,100);
    nowyear = atoi(tempnowyear);
//printf("tempnowyear %s\n",tempnowyear);
   
    substring(4,6, nowdate, tempnowmonth, sizeof nowdate);
    nowmonth = atoi(tempnowmonth);

    substring(6,8,nowdate,tempnowday,sizeof nowdate);
    nowday = atoi(tempnowday);

//printf("now year str %s %s %s\n",tempnowyear,tempnowmonth,tempnowday);
//printf("now year int %d %d %d\n",nowyear,nowmonth,nowday);

//printf("diff %d\n",diff);

    prevday = nowday - diff;
    if (prevday <= 0){
        prevmonth = nowmonth - 1;

Techno Vocab 3

1. ) Bluetooth เป็นการเชื่อมต่ออุปกรณ์สองตัวเข้าหากันด้วยความถี่คลื่นที่ 2.4 GHz ซึ่งมีระยะการทำงานที่สั้นได้ประมาณ 30 ฟุตเป็นอย่างมากในที่โล่ง จุดประสงค์ที่เขาสร้าง Bluetooth ขึ้นมาก็เพื่อมาแทนที่สายไฟ เช่น Palm กับ โทรศัพท์มือถือ หรือ โทรศัพท์มือถือ กับ Small talk แต่มีข้อจำกัดเรื่องของระยะทางและความเร็วในการรับส่งข้อมูล

2. ) Wi-Fi เป็นการสื่อสาร ข้อมูลแบบไร้สายที่รวดเร็ว เหมาะที่จะนำมาสร้างเครือข่ายไร้สายสำหรับการเชื่อมคอมพิวเตอร์เข้าหากัน สามารถสื่อสารได้ไกลและมีความเร็วที่สูงกว่าการใช้ Bluetooth การทำงานคล้ายกับระบบ Network แบบมีสาย

3. ) Worldwide Interoperability for Microwave Access หรือ WIMAX เป็นมาตรฐานการเชื่อมต่อ Internet แบบไร้สายด้วยความเร็วสูง ถูกออกแบบมาให้ใช้ได้ทั้งภายในและภายนอกอาคาร และมีพื้นที่การใช้งานที่ครอบคลุมได้มากเช่นกัน ถือว่าเป็นการสื่อสารข้อมูลที่มีประสิทธิภาพที่ดีมากกว่า Wi-Fi

4. ) SIGTRAN คือ เป็นการใช้เครือข่ายคอมพิวเตอร์ TCP/IP ในการส่ง signaling C7 ที่ใช้ใน telecom network แทนระบบ transmission แบบ TDM(Time Division Multiplexing) เพื่อรองรับปริมาณลูกค้าที่เพิ่มขึ้น

5. ) Signalling Gateway เป็นอุปกรณ์ในระบบ SIGTRAN ทำหน้าที่ในการเชื่อมต่อและแปลงข้อมูล signaling C7 TDM เดิม ให้เป็นข้อมูลบนเครือข่ายคอมพิวเตอร์ TCP/IP

6. ) Time Division Multiplexing over The Internet Protocol หรือ TDMoIP คือ เทคโนโลยีในการรับส่งข้อมูล ที่ทำให้สามารถส่งต่อ T1, E1, T3 หรือ E3 circuit ผ่าน Packet-switched Network ซึ่งเป็นรูปแบบสัญญาณหรือ interface ที่ใช้ในการเชื่อมต่อข้อมูลของชุมสายต่างๆได้

7. ) MultiProtocol Label Switching หรือ MPLS เป็นการเพิ่มประสิทธิภาพของการรับส่งข้อมูลใน IP Network ให้มีความเร็วและคุณภาพของการรับส่งข้อมูลที่ดีขึ้นกว่าเดิม และมีความเร็วในการค้นหาข้อมูลที่เร็วกว่า Router รวมทั้งความสามารถในการทำ Traffic Engineering , Virtual Private Network เป็นต้น

Techno Vocab 2

1.) CDMA คืออะไร ระบบ CDMA (Code Division Multiple Access) เป็นพื้นฐาน ในเรื่อง การสื่อสารและส่งข้อมูลผ่านคลื่นความถี่ ของ ระบบ CDMA ซึ่ง คู่ติดต่อสื่อสาร จะสามารถใช้ คลื่นความถี่ ( Frequency) ทั้งแถบ สำหรับการติดต่อระหว่าง ผู้รับและผู้ส่งสัญญาณโดยเฉพาะตลอดระยะเวลาการติดต่อ โดยการติดต่อสื่อสารในแต่คู่นั้นจะถูกการเข้ารหัสสัญญาณ ( Coding) ก่อนนำส่งผ่าน คลื่นความถี่ ซึ่งเทคโนโลยีนี้นั้นเองที่สามารถทำให้ คู่ติดต่อสื่อสารจะสามารถส่งข้อมูลได้มากขึ้น และเร็วขึ้น เมื่อเปรียบเทียบกับ FDMA และ TDMA

2.) Softswitch คือเทคโนโลยีที่ทำให้อุปกรณ์ซึ่งทำงานบนพื้นฐานของซอฟต์แวร์สามารถทำหน้าที่เช่นเดียวกับอุปกรณ์สวิตชิ่งในโครงข่าย PSTN สามารถรองรับบริการที่อยู่ในรูปแบบของแพ๊กเกตโดยสามารถทำงานร่วมกับโครงข่ายแบบวงจรสวิตซ์ได้ ที่สำคัญคือโครงสร้างของ Softswitch มีลักษณะแบบเปิดและแยกส่วน ต่างจากโครงข่ายแบบวงจรสวิตซ์เดิมที่มีลักษณะปิด ข้อดีคือเปิดโอกาสให้ผู้ผลิตอุปกรณ์โครงข่ายทั้งหลายสามารถพัฒนาอุปกรณ์ที่ตั้งอยู่บนมาตรฐานสากลเดียวกัน ทำให้อุปกรณ์ที่ผลิตได้มีลักษณะเฉพาะเป็นของตัวเอง

3.) HSDPA = HIGH SPP HSDPA = HIGH SPEED DOWNLINK PACKET ACCESS เป็นเทคโนโลยีที่ใช้การปรับปรุงสัญญาณวิทยุของ 3G Network (มาตรฐาน UMTS )ซึ่งเดิม UMTS จะสามารถส่งข้อมูลได้สูงสุด 2 Mbps แต่อุปกรณ์ Commercial จะทำได้ประมาณ 384 kbps เท่านั้น HSDPA Phone และ Base Station จะช่วยเพิ่มการรับส่งให้ทำได้ถึง 1.4 Mbps ซึ่งพิสูจน์แล้วในการใช้งานจริงไม่ใช่แต่ในทางทฤษฎี (กำหนดการ Commercial ของ Supplier ประมาณ Q4,2005 )

4.) Black Berry เป็น Wireless Application ที่ใช้สำหรับรับ-ส่ง Email และ Coporate Application อื่นๆ ซึ่งจำเป็นต้องใช้ Terminal ที่ออกแบบมาโดยเฉพาะเท่านั้น(Black Berry Phone) และ Application ที่รับส่งกันระหว่าง Application Server กับ Phone จะมีขนาดเล็กสามารถส่งบน GPRS Network ได้นอกจากนั้นยังมีลักษณะเป็น Push Service เช่น สามารถ Alert และรับ Email ได้ทันทีที่มีคนส่งมาหา

Syndicate content