LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-02-2016, 09:48 AM   #16
tashman1989
LQ Newbie
 
Registered: Aug 2016
Posts: 10

Original Poster
Rep: Reputation: Disabled

kindly find below result /usr/sbin/postqueue -p

Code:
[root@hostsvr /]# /usr/sbin/postqueue -p
Mail queue is empty
[root@hostsvr /]#
 
Old 09-02-2016, 09:50 AM   #17
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,370

Rep: Reputation: 387Reputation: 387Reputation: 387Reputation: 387
Hi

The problem is this command:

Code:
/usr/sbin/postqueue -p | tail -n1 | awk '{print $5}'
If you have postfix installed and mails in the queue, it will tell you the number of mails in the queue. But if the queue is empty, postqueue -p will simpy say "Mail queue is empty", and it will be filtered away by awk. I guess the person who wrote that script never had an empty mail queue

You can multiply with 1 in awk to always get a number (nothing multiplied by 1 is 0)

Code:
queuelength=`/usr/sbin/postqueue -p | tail -n1 | awk '{print $5 * 1}'`
 
Old 09-02-2016, 09:54 AM   #18
gda
Member
 
Registered: Oct 2015
Posts: 119

Rep: Reputation: 25
Well done Guttorm!
 
Old 09-02-2016, 09:58 AM   #19
tashman1989
LQ Newbie
 
Registered: Aug 2016
Posts: 10

Original Poster
Rep: Reputation: Disabled
Smile

Thanks Guttorm the script will not work if the mailq is empty and I appreciate your effort and help gda

Thanks All
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
bash script error : integer expression expected linuxandtsm Linux - Newbie 7 01-07-2014 06:01 AM
[SOLVED] Error in Shell script if then - line 21: [: 0.38: integer expression expected Lucard Linux - Newbie 3 04-17-2013 11:42 AM
[: : integer expression expected if else condition Iyyappan Linux - Server 4 11-25-2012 02:09 AM
[SOLVED] if condition error: integer expression expected Kashif_Bash Programming 6 04-18-2012 05:37 AM
Error upgrading kernel, /sbin/mkinitrdi integer expression expected amp2000 Linux - General 2 12-05-2003 05:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:07 AM.

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