2014-06-26 56 views
0

我正在使用RedHat(rhelsvrbase64-6.2)版本。 我已經編寫了一個incron作業來將文件(即utf-16le格式)轉換爲UTF-8格式。創建多個文件的Incron作業

When i am running my job, It is creating multiple UTF-8 copies of my file. 

    My incrontab script is as follows: 

    **/home/sap/SRMArchive/incronTest IN_CLOSE_WRITE /usr/local/bin/test.sh [email protected] $#** 

    test.sh 

    **#!/bin/bash 
    echo "hi">>/var/log/my.log 
    echo $1>>/var/log/my.log 
    echo $2>>/var/log/my.log 
    file -bi $1/$2 >>/var/log/my.log 
    iconv -f utf-16le -t UTF-8 $1/$2 > $1/UTF8_$2** 

    When i am dropping any file to my '/home/sap/SRMArchive/incronTest' folder, The output i am getting is number of files named as follows : 

    UTF8_myFile.txt 
    UTF8_UTF8_myFile.txt 
    UTF8_UTF8_UTF8_myFile.txt 
    UTF8_UTF8_UTF8_UTF8_myFile.txt 
    ......... 
    ........ 


Thanks in advance 

回答

0

在這一行:

iconv -f utf-16le -t UTF-8 $1/$2 > $1/UTF8_$2** 

你正在創造你與incron觀看同一個目錄中的輸出。當iconv完成寫入文件時,會得到一個新的IN_CLOSE_WRITE事件,該事件會使用輸出文件的名稱觸發腳本,等等。

理論上,你應該得到一個無限循環。

解決方法是(a)在不同目錄中生成輸出,或者(b)讓腳本忽略以UTF8_開頭的文件上的事件。