General
cancel
Showing results for 
Search instead for 
Did you mean: 

script for File exist or not...

friend_1
Occasional Advisor

script for File exist or not...

Hi,

one application is running on my server. that application will create one log file . when creating that log file automatically send mail from that server.that log file will be available for some time then i will be deleted. after deleting that file i should receive mail .

How to write sript for this? please help

Thanks in advance

2 REPLIES
Goran Koruga
Honored Contributor

Re: script for File exist or not...

Hello.

Use your shell's test built-in:

man 1 test
man bash

For bash this is documented under CONDITIONAL EXPRESSIONS section of the man page.

The most trivial:

if [ -f /path/to/file ]
then
echo file exists
else
echo file not there
fi

Another option is to use inotify subsystem with tools like incron, inotify-tools or iwatch.

Regards,
Goran
Andrew Cowan
Honored Contributor

Re: script for File exist or not...

You could also use:

if [ -r file]

because if it is there but you can't read it due to permissions, it won't be a lot us of use to you?