LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-28-2007, 05:00 AM   #1
151803
LQ Newbie
 
Registered: Jan 2007
Posts: 22

Rep: Reputation: 15
Mailing in Linux scripting.


Hi,
I have written a linux script with mailing mechanism which is included in crontab to excute once in an hour.But,the problem is that when the script is being executed once in an hour,I am getting two mails with an inetrval of 1 minute whereas I am supposed to get one mail.Can anyone please help me in this?
 
Old 05-28-2007, 05:04 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

What does the script and the crontab entry look like?
Without that info it's hard to guess what could be wrong
 
Old 05-28-2007, 05:14 AM   #3
151803
LQ Newbie
 
Registered: Jan 2007
Posts: 22

Original Poster
Rep: Reputation: 15
The crontab looks like as below:

0-59/59 * * * * /bin/bash -l /home/mquser/apache-tomcat-4.1.34/webapps/ReportTemplate/Util/NodeStatus.sh

The script is supposed to send one notification mail when one of the server is down.I have pasted a part of the script(for 1 server) as below:

#! /bin/bash
#echo Hello!
export JBOSS_CLASSPATH=/home/xmuser/CQ/opt/eccc/jboss/client/jbossall-client.jar
sender_email=middleware@uniform.aramark.com
receiver_email=kaushik.das@uniform.aramark.com,debasish.mishra@tcs.com,vivek.choudhary@tcs.com

/home/xmuser/CQ/opt/eccc/jboss/bin/twiddle.sh -s 10.29.126.40 get --noprefix jboss.system:type=ServerInfo HostName > /home/mq
user/apache-tomcat-4.1.34/webapps/ReportTemplate/Util/serverinfo.txt

FILE_TEXT=`cat /home/mquser/apache-tomcat-4.1.34/webapps/ReportTemplate/Util/serverinfo.txt`
txtFlag=`echo $FILE_TEXT | grep bootes2`
echo $txtFlag

if [ -z "$txtFlag" ]
then
echo " BOOTES2 " > /home/mquser/apache-tomcat-4.1.34/webapps/ReportTemplate/Util/SingleNodeStatus.txt
echo "Server Down " >> /home/mquser/apache-tomcat-4.1.34/webapps/ReportTemplate/Util/SingleNodeStatus.txt
subject="BOOTES2 Server(10.29.126.40) is down on `date` "
serverstatus='/home/mquser/apache-tomcat-4.1.34/webapps/ReportTemplate/Util/nodestatus.txt'
echo "Subject: ${subject}" > ${serverstatus}
cat /home/mquser/apache-tomcat-4.1.34/webapps/ReportTemplate/Util/SingleNodeStatus.txt>> ${serverstatus}
/usr/sbin/sendmail -f $sender_email $receiver_email < ${serverstatus}
else
echo " BOOTES2 " >> /home/mquser/apache-tomcat-4.1.34/webapps/ReportTemplate/Util/SingleNodeStatus.txt
/home/xmuser/CQ/opt/eccc/jboss/bin/twiddle.sh -s 10.29.126.40 get --noprefix jboss.system:type=Server StartDate >> /
home/mquser/apache-tomcat-4.1.34/webapps/ReportTemplate/Util/SingleNodeStatus.txt
fi

Please advice........
 
Old 05-28-2007, 07:37 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

The crontab entry looks incorrect, here's one possible way:

0 * * * * /home/mquser/apache-tomcat-4.1.34/webapps/ReportTemplate/Util/NodeStatus.sh

The /bin/bash -l part isn't needed.

Your script also has a strange (copy-paste related?) entry:

- Is the user/apache-tomcat..........serverinfo.txt line part of the previous line? The next line also mentions this line, but it is put in a variable.

- The first line should be: #!/bin/bash (no space, although I think that bash is forgiving with this 'error').

- Maybe sendmail can use a comma separated entry for the mail receivers, but I do think that this line:
receiver_email=kaushik.das@uniform.aramark.com,debasish.mishra@tcs.com,vivek.choudhary@tcs.com
should be:
receiver_email="kaushik.das@uniform.aramark.com debasish.mishra@tcs.com vivek.choudhary@tcs.com"

Hope this helps.
 
Old 05-30-2007, 04:49 AM   #5
151803
LQ Newbie
 
Registered: Jan 2007
Posts: 22

Original Poster
Rep: Reputation: 15
Hi,
Actually there are two crontab entries but the other one is working fine.So,I do not think there is anything wrong related to crontab entry.
And also the mailing part in the script is correct as the other script is working fine with the same mailing part.
Please look if there is anything wrong in the script and advice.....
 
Old 05-30-2007, 09:13 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Maybe you're not clear enough, but I conclude the following: 2 crontab jobs for the same shellscript = 2 times executed = 2 mails. You probably mean something else

What about the other 2 things I pointed out? (/bin/bash line and the user/apache line) any luck with that?

Did you try altering the crontab to what I suggested or did you assume that the line is ok.

One other thing, post the whole script if you want us to look at it, not only the part that you think is relevant. And put code tags around it, makes reading it a lot easier.
 
Old 05-31-2007, 01:17 AM   #7
151803
LQ Newbie
 
Registered: Jan 2007
Posts: 22

Original Poster
Rep: Reputation: 15
Hi,
the issue is resolved.I made some changes in the crontab entry
as below:
0 0-23/1 * * * bin/bash -l /home/mquser/apache-tomcat-4.1.34/webapps/ReportTemplate/Util/NodeStatus.sh


Anyway thanks for your help....
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux Mailing with Exchange lapthorn Linux - Enterprise 10 05-03-2006 11:43 AM
Linux Mailing DARSHAND Linux - Software 1 12-15-2005 07:34 AM
Scripting and mailing akilles Linux - Newbie 9 10-01-2004 10:21 AM
Linux mailing lists moger Linux - General 5 01-17-2004 01:17 PM
redhat linux mailing list keevitaja Linux - Security 1 03-20-2003 06:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration