Validation in shell script.

PICKUPDIR=/home/ready/
DROPDIR=/home/downloaded/
TODAY=$(date '+%d%m%y')
LOGFILE=xyz-$TODAY.log
###########
#FUNCTIONS#
###########
#function to perform file transfer to servercopy folder
opalO ()
{
cd $PICKUPDIR
for fileName in `ls -1 TES_ONE*`
do
cp $fileName $DROPDIR
done
} >> $LOGDIR/$LOGFILE
#############
#Main Script#
#############
echo "Start trnasfer to downloaded \c" >> $LOGDIR/$LOGFILE 
date >> $LOGDIR/$LOGFILE
opalO
wait
echo "Start file renaming: \c" >> $LOGDIR/$LOGFILE
date >> $LOGDIR/$LOGFILE
cd $PICKUPDIR
for FILE in `ls Tes_ONE*.*`
do
echo ${FILE} " : File Moved" >> $LOGDIR/$LOGFILE
mv ${FILE} ${FILE}.arch 
done
echo "End" >> $LOGDIR/$LOGFILE
exit 0

opalO function transfer the files from 'ready' to 'downloaded' folder.
I want to keep validation,if there is no files (TES_ONE*) in ready folder then an error message(No Files Availble) should go into the log file.
How can i place this validation in the above code? Please assist me.

Thanks in advance.

Try this:

opalO ()
{
  if [ -f "$1" ]; then
    for fileName in "$@"
    do
      cp "$fileName" "$DROPDIR"
    done
  else
    echo "no files available"
  fi
}

opalo TES_ONE*
1 Like

Please help me to handle below scenerio -

1) File abc.txt has approx 10,000 records in it. It can have more records.
2) Above, script to be executed to transfer the file from ready to downloaded folder
3) There is a process �load' which checks every ready directory every minute. If it finds the file in downloaded folder then the process �load' picks the file and passes this to
another process.

Is there any possibility, before transferring all the records, process �load' will pick the file as soon as kept in downloaded folder? If yes, kindly provide me the solution for this.

---------- Post updated 11-09-10 at 04:28 PM ---------- Previous update was 11-08-10 at 06:29 PM ----------

Kindly reply to my query.

---------- Post updated at 05:10 PM ---------- Previous update was at 04:28 PM ----------

Hi,

solution provided worked fine but i want one enhancement to add.
Actually if there is no file in ready folder then the further statements, to rename the file to .arch, should not be executed.

Kindly help me as i am quite newi n writting the shell scripts.

Thanks a lot.

---------- Post updated 11-10-10 at 12:49 PM ---------- Previous update was 11-09-10 at 05:10 PM ----------

Hi,

Kindly reply on my queries.

Thanks

Adding an if condition to your code would do the job i believe

cd $PICKUPDIR
if [ -f "${PICKUPDIR}*" ]
then
	for FILE in `ls Tes_ONE*.*`
	do
		echo ${FILE} " : File Moved" >> $LOGDIR/$LOGFILE
		mv ${FILE} ${FILE}.arch 
	done
fi
echo "End" >> $LOGDIR/$LOGFILE
exit 0
  1. Check out inotifywait on Linux.