0

I am using RedHat (rhelsvrbase64-6.2) version. I have written an incron job to convert a file(i.e. in utf-16le format) to UTF-8 Format.

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 $@ $#**

    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
4

1 回答 1

0

在这一行:

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

您正在与正在观看的同一目录中创建输出incron。完成iconv文件写入后,您会收到一个新IN_CLOSE_WRITE事件,该事件会使用输出文件的名称触发您的脚本......等等。

从理论上讲,您应该从中获得无限循环。

解决方案是 (a) 在不同的目录中生成输出,或者 (b) 让脚本忽略以 . 开头的文件上的事件UTF8_

于 2014-06-26T12:19:57.340 回答