To find a file name

Hi,

May I know is it possible, when a file named with the extension *.cgi runs in my box, I need a mail authentication...

go through the man page of ps command
like

 
if [ `ps -ef|grep *.cgi|wc -l` -gt 1 ] ; then
echo "CGI is running"
else
echo "not running"
fi

Hi vidyadhar85, Thank you for your reply, but is it possible to set up with the email authentication when this *.cgi files runs in my box.

I have set up in the cron the above script that will be running every 15 mins and will send an email notification to respective email id.
This is my cron
*/15 * * * * /bin/sh /root/find.sh | mail -s "CGI Script `date` `time`" <email id >

This scripts check for the *cgi file running in the box, if the *cgi file is running , it will send a message as "Cgi is running" , if not "Not running". rather than this type of option, i need as if *.cgi runs i need the mail notification if not i don't need the email notification.

Hi,

Can you please help me on my request....

you can put a && instaed if | in cron entry

if the out put of find.sh is 0 then it will send the mail
if its >0 no mail is sent.
You have the adapt the find.sh to give a output

Hi,

What is the use of changing the cron from | to &&.. -> what will happen if we change to this...

also, I am not sure how to make changes to stop mail when the particular file is not running... I am not good in programming. Please help me on this ...

"&&" means if the run before the "&&" is successful (returns 0) then also run what is after the "&&" otherwise do not run what is after the "&&". In other words a mail messages is sent only when the /root/find.sh script sees a *.cgi process running.

/root/find.sh needs to contain:

if [ `ps -ef|grep *.cgi|wc -l` -gt 1 ] ; then
  exit 0
else
  exit 1
fi

If you want the process line mailed also than find.sh could do:

if [ `ps -ef|grep *.cgi|wc -l` -gt 1 ] ; then
  rm /tmp/cgimailcontents 2>/dev/null
  ps -ef | grep cgi | grep -v grep > /tmp/cgimailcontents
  exit 0
else
  exit 1
fi

and the cron job would then be:

*/15 * * * * /bin/sh /root/find.sh && mail -s "CGI Script `date` `time`" <email_id > < /tmp/cgimailcontents

N.B.

  1. "*/15" does not work in cron for all Unixes, you may need to (e.g. for Solaris) use "0,15,45" instead.

  2. Every 15 minutes is not very frequent and if the CGI script only runs for 2 minutes you may miss it!

  3. The "/bin/sh" is not necessary if the /root/bin.sh script is chmodded to be executable by user running the crontab, unless the /root/ filesystem is mounted with the -noexec option in which case the /bin/sh overcomes that!

Thank you for your detailed information.

Let me check within my box and will update you if I have any doubt...