I have a script which checks for *.txt files in a particular directory and if no files were found then it goes into sleep for 10 secs and looks back for files again and if any files were found then the script does some processing with the files found, which is my requirement too.
FILE_EXISTS=`ls ${INPUT_DIR}/*.txt | wc -l`
if [ $FILE_EXISTS -eq 0 ];
then
echo "No file found hence sleeping for 10 secs..."
sleep 10;
continue;
fi
but when ever no files were found a message saying
ls: 0653-341 The file /home/sys/*.done does not exist.
Is being displayed which I do not want to be displayed. So I used
>/dev/null 2>&1
in the script as below
FILE_EXISTS=`ls ${INPUT_DIR}/*.txt >/dev/null 2>&1 | wc -l`
if [ $FILE_EXISTS -eq 0 ];
then
echo "No file found hence sleeping for 10 secs..."
sleep 10;
continue;
fi
now the message is not being displayed but even if files exists in the directory, the file count is not being assigned to the variable FILE_EXISTS. Doing so the script does not go further to do the required file processing but instead it still goes into sleep for 10 secs. Could any one please suggest any correction which needs to be made to my script.