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
In this line:
You are creating your output in the same directory you're watching with
incron
. Wheniconv
finishes writing the file, you get a newIN_CLOSE_WRITE
event, which triggers your script with the name of the output file...and so forth.In theory, you should get an infinite loop out of this.
The solution is either (a) to generate your output in a different directory, or (b) have your script ignore events on files that begin with
UTF8_
.