HI folks,
can any one tell me how to check whether the file is existed in a directory or not .
let me tell you my requirement : if the file is existed i should display a one message or else i have to send a mail ..
i have the mail logic .. but I'm failed to check file existence .. please help me asap guyss
fileName="abc.txt"
[ -f $fileName ] && echo "File Present" || echo "File Not Present" | mail -s "File Not Present" abc@abc.com
try with below
if [ -f filename ]; then
echo "file exists"
else
echo "file does not exist"
#here you can put the logic for sending mail
fi
Cheers
Harish
i have to check 14 files guys , so shall i use 14 if statements r wt ?? any idea
---------- Post updated at 11:10 AM ---------- Previous update was at 10:50 AM ----------
@ abv now im using this code .. but i'm facing some problem guys . can you tell me whether it will work or not ..please
in_file=$Input_Dir"ksk-cvd_"$last_date.*
if [ -e $in_file ]
then
echo "$in_file">> $Log
echo "`date` File download successful to London application server..">> $Log
unix2dos ${var} | uuencode ${var} | mailx -s "MISSING one file" 'xyz@gmail.com'
else
echo "`date` File download failed .">> $Log
exit 1
fi
put all the 14 files inside the file called input.txt
while read fileName
do
if [ -e $fileName ]
then
echo "$fileName">> $Log
echo "`date` File download successful to London application server..">> $Log
unix2dos ${var} | uuencode ${var} | mailx -s "MISSING one file" 'xyz@gmail.com'
else
echo "`date` File download failed .">> $Log
exit 1
fi
done < input.txt
thanks for the reply .. let me check dude ..