Mail Queue

I know the command "mailq" can be used to check any mail is pending , if I would like to get the alert if the no. of pending mail is over 500 , would advise what can I do , if a script can do that ? very thanks


Similar Content



Grep Output Of Command To Return 1 Or 0 For If Then Statement

So, I'm new here. Was thrown into the deepend (read: shallow pool) of linux administration of a few centos 6.5 servers in October, and I've been pretty slow on the uptake. Years of Windows administration and desktop support will do that I guess.

So we have qmail on our prod servers that send out messages for our webapps. Postfix failed last night on a prod server, and it occurred to me that it's happened a few times since I've started, and instead of waiting for clients to tell us, I should be more proactive. I came up with/begged/borrowed/stole a quick script to check to see if postscript was running, and if it was, restart it, and contact us. This was to be run from jenkins.

Quote:
if (( $(ps -ef | grep -v grep | grep postfix | wc -l) > 0 ))
then echo 'Mail is up.'
else echo 'Mail is down! Attempting to restart service...'
service postfix restart
fi
The question was then raised about an unresponsive process (zombies!), and I figured it might be a better idea to use postqueue -q, or mailq to either see a Mailbox is empty, or look for fatal if postfix is off or unresponsive. This is where I ran out of coffee and went over the deep end.

To get this to work, I thought it would be a good idea to run two scripts. One to check if the mail queue is empty, and if not, send up a flag. The next was to run a few minutes later to check and see if the mail queue was throwing up a fatal error, and if it was, throw up a second flag, which sent out an email from jenkins. Incidentally, if the mailqueue were clogged, this would also trigger an alert. Our mailqueue doesn't get a lot of traffic.

First command. Returns then and else statement without issue.
Quote:
if ((mailq | grep 'empty') < 0 ); then echo 'Mail is up.'; else echo 'Mail queue is not empty. Please check mail server'; fi
Second one... Not so much.
Quote:
if (mailq | grep 'fatal') < 1; then echo 'Mail is up.'; else echo 'Mail queue is not empty. Please check mail server'; fi
You can probably suss out what I'm trying to do here, even though I'm not doing it right. Any ideas? I know this is newbie stuff, and I appreciate your taking the time to read this people.

Best Way To Run Two Interdependent Scripts

Hi All,

I have two scripts, the aim of these two scripts is, to check whether a particular script is running or not, if it wont runs, then throw a mail.

How i Achieved this output is, I wrote first script.

I created an infinite while loop which performs below steps

1. It creates a touch file
2. Triggers the script which needs to be monitored if its working or not.
3. Removes the touch file.

If the second step fails, then the remove file command will not happen and the script will stuck there itself.

I created an another script which checks the creation time of the touch file and if it is more than ten minutes, it means the second step in the first script is hanged, which also means that particular script is not working.

So if the creation time is more than 2 minutes the second script will throw a mail.

Below are the two scripts.

Code:
#!/bin/ksh



userid="chansd"

filename="/apps/log/check.txt"

while true ;do
touch $filename
pass=`/apps/eDMZ/call_st.ksh $userid`
sleep 20
rm $filename
done

Below script checks the file creation time and throws email if it is older than 2 minutes
Code:
#!/bin/ksh


filename="/apps/log/check.txt"

if [ -f "${filename}" ]
then
if test "`find $filename -mmin +2`"
then
echo "script is not working ! Please act on it" | mail -s "Script  is not working" Example@mail.com
fi


else

        exit 1

fi


What im going to do is

1. I am going to run the first script in background so it runs forever.
2. I am going to run the second script in cron forevry 5 mins to check the file creation time.

3. So if the first script hangs . I will kill the process using process id and after the issue resolves with the inner script, I will run the main script again.

I am new to Linux, Please let me know if this approach will work as expected.

Bash More Commands In One Function

hello

first year of learning linux and bash script
Now i wrote a bash script with a function.
Today i recieved a email from my teacher that 1 function only can have 1 command and no more then 1?

thats a part of the script

Code:
function tx_unreachable_msg()
{
LOGLINE="[$DATE] no ip service unreachable"
typewriter "$NOIPSERVICE niet bereikbaar" .1
sleep 1 
typewriter "Mail wordt verzonden naar $email" .1
mail -s "NO ip mail error" "$email"<<EOF
dynupdate.no-ip.com niet bereikbaar @ $DATE
EOF
}

it's part dutch part english but the point is that the first LOGLINE is forbidden in the function because i use the functie to send a mail end not to write a logline but that's a part of the command in my case?

So what does this function?
If the no ip service is unreachable then it's write to /etc/var/log/no-ip and after the sleep it's send a simpel mail to the adres in the variabele mail.

i read here at the first line:
Quote:
Shell functions are a way to group commands for later execution using a single name for the group.
so is it true that my function is wrong and so no can someone point me to a website where it's say that more commands are allow in 1 function0

grts b

Sending Mails With Port Number 587 Bash Script Help

Hi All,
We have some shell scripts which will send emails about backup, alerts etc using mail command. Example.
Code:
echo "Test Mail" | mail -s "Test" me@mydomain.com

I guess the above command just connect port number 25 of our mail server even if we do not define any port number. Now I would like add smtp port number as 587 in all of the bash scripts. I googled for this but could not get whatever I am expecting. So expecting your kind reply to define smtp port number as 587 in all of the bash scripts.

Thanks in advance.

Sending Mail From Command Line

I searched the forums for my title and I am not finding exactly what I am looking for. I am not using a program to send mail, such as Thunderbird or whatever. I simply want to be able to send mail from my Ubuntu 14.04 DESKTOP version for logging. I use a program called Logwatch (used alot in RHEL or CentOS) to monitor the server itself. The program sends mail to the root user account on the machine, which I can check and see, and within the program conf file, I can add an external email address, but it never sends.

I'm familiar with the SMTP concept of sending mail, outgoing mail server authentication, etc. I don't care to run this box as an SMTP server, but I understand that I need some sort of SMTP or MTA program to send mail into the real world. I tried Postfix but couldn't get that to work, and the Logwatch program wants to use sendmail, so I installed that but I am having the same issue. I am sure it is a step I am missing.

I also can't figure out how to get the 'mail' cmd from Terminal to work. I use this command:
Code:
mail -s "test" | /usr/sbin/mail myemail@domain.com

it follows through the subject, CC, body, but when I try to hit either . or CTRL-D, it never sends the email, in fact is does nothing.

I also tried sendmail with this command:
Code:
sendmail -v my@email.com < /dev/null

I was just trying to send a test email. It logs into my SMTP mail server, which I already configured, and it tells me to type out the mail, then end with a "." by itself on a single line. I try this and it just sits there.

I am missing SOMETHING when trying to actually send the mail. I can get it written with subject and body, connected, but it never sends and I am probably missing a / or something.

I did find and follow these instructions, but it still isn't working with sendmail. If I need to go back to Postfix, I can do that, I don't honestly care what I use, I just want some programs such as Logwatch to be able to email me.
http://stackoverflow.com/questions/1...mail-on-ubuntu

Sendmail Alias Not Working

I'm trying to send all root's mails to an external e-mailaddress, but for some reason I can't get it to work.

I've edited /etc/aliases with the following rule:

root: <myexternal@email.address>

and run newaliasses after, which would run without any errors.

I can run: echo "Testing" | mail -s "Server Testing" <myexternal@email.address>
just fine without any issue and it's being delivered correctly to my external address.

But when I run: echo "Testing" | mail -s "Server Testing" root

I (first) get a "Deferred: 451 Temporary local problem - please try again later" error and when I then run: "Sendmail -OTimeout.hoststatus=0m -q -v" to flush the mailqueue it says everything is ok, but I then get a message saying I have new mail in /var/spool/mail/root and I don't get the mail on my external e-mailaddress.

I have no clue where to look next, hopefully you guys can point me in the right direction.

Just for completeness: I use mageia release 4 (x86_x64).

Mail Configuration

I congifured postfix,dovecot and squirrelmail in my server. Now I am able to send mail from my webmail ( squirrelmail ) to my office email address, while I am trying to reply for that mail I didnt face any error. Mail logs also show that mail has been deleivered. But I didnt get any emails in my inbox, all the folders except inbox( sent, trash and drafts) were working fine. But I dont know what is the issue with inbox. I have checked all the configuration files.
I am using Ubuntu 12.04.5 LTS .any one have idea about this issue?

Sendmail Is Not Working

Hi all,

I am trying to configure sendmail on my OEL 6.5 running on VM.

I did below to set it :

1. # yum install m4 telnet mailx
2. # yum install sendmail sendmail-cf
3. # ps -ef | grep -v grep | grep -i sendmail
root 3805 1 0 05:58 ? 00:00:00 sendmail: accepting connections
smmsp 3815 1 0 05:58 ? 00:00:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue

4. # netstat -an | grep :25 | grep tcp
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN

5. vi /etc/mail/sendmail.mc

From:
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

To
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

6. # m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

7. # service sendmail restart

8. # vi /etc/mail/local-host-names
oracle.com

Now if I am sending mail from 1 user (root) to other user (oracle)

$ mail -s "Test mail from root" oracle
Hello this is the test mail
.
EOT

and checking mail log under /var/mail/oracle, its passing successfully.

But when trying to send the same from root user to my company outlook account not gtting any mail.

mail -s "Test mail from root" abc.xyz@aaaa.com (trying to send to my outlook account)

Getting below error on /var/log/maillog :

May 13 10:47:47 mydb sendmail[6306]: t4DEllUD006306: from=oracle, size=244, class=0, nrcpts=1, msgid=<201505131447.t4DEllUD006306@mydb.oracle.com>, relay=root@localhost
May 13 10:47:47 mydb sendmail[6307]: t4DEllxo006307: from=<oracle@mydb.oracle.com>, size=506, class=0, nrcpts=1, msgid=<201505131447.t4DEllUD006306@mydb.oracle.com>, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1]
May 13 10:47:47 mydb sendmail[6306]: t4DEllUD006306: to=abc.xyz@aaaa.com, ctladdr=oracle (600/601), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30244, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (t4DEllxo006307 Message accepted for delivery)
May 13 10:47:49 mydb sendmail[6309]: STARTTLS=client, relay=mail1.nic.aaaa.com., version=TLSv1/SSLv3, verify=FAIL, cipher=AES256-SHA, bits=256/256
May 13 10:47:50 mydb sendmail[6309]: t4DEllxo006307: to=<abc.xyz@aaaa.com>, ctladdr=<oracle@mydb.oracle.com> (600/601), delay=00:00:03, xdelay=00:00:03, mailer=esmtp, pri=120506, relay=mail1.nic.aaaa.com. [192.240.6.6], dsn=2.0.0, stat=Sent (1uc8dar1s7-1 Message accepted for delivery)

Please suggest if something I missed out or any other problem

Thanks,

Qmail Help

Hi All,
We have qmail server running on RHEL6.5. We have already made sure that our server is not acting as an open relay with the help of http://mxtoolbox.com/diagnostic.aspx.
But still anyone can telnet to our domain and send fake emails to anybody@ourdomain.com. For example Code:
telnet mail.ourdomain.com 25
helo mail.ourdomain.com
mail from: unknown@anyname.com
rcpt to: anyemailid@ourdomain.com
data
from: "Any Unknow name" <unknown@anyname.com>
to: "Some user Name" <anyemailid@ourdomain.com>
subject: Testing MTA with telnet

Hi,
This way anybody can fool us.

Regards,

.
quit

So can anybody pls help me to prevent this. I meant to say, we should not block port 25, instead it should verify whether or not "from email id" is exist in our domain, if it is exist then it should ask for the password also or if it is not exist then also it should not take us to next step. Because as per above example anybody can fool us as the mail is coming from outside but it is just from our domain to our domain without any authentication!!!
Expecting your kind help to block sending mails in this way.

Linux Mail Server

Hello Guys,

I set up a mail server in a LINUX environment using iRedMail.The users can only send and receive e-mail throughout the local network, not from the Internet. I would like to know the steps to follow for the configuration. Also i want the windows users to be able to send and receive e-mails through that mail server.
Thanks to help...