Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-18-2012, 11:18 AM   #1
LQ Newbie
Registered: Jun 2012
Posts: 2

Rep: Reputation: Disabled
Script Variable Value

I have the following script that wipes the queue of all emails from a particular sender.

mailq | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if ($7 == "") print $1 } ' | tr -d '*!' | postsuper -d -

I'd like to set this up in a shell script named and execute it with the email address defined. I tried the following but it just stares at me when I execute the script.

mailq | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if ($7 == "$EMAIL") print $1 } ' | tr -d '*!' | postsuper -d -

If I do:


it doesn't replace $EMAIL in the script with the value defined.

What am I doing wrong?

Script noob

Last edited by ehren8879; 06-18-2012 at 11:20 AM.
Old 06-18-2012, 12:51 PM   #2
Registered: Oct 2011
Location: USA
Distribution: Red Hat
Posts: 259
Blog Entries: 9

Rep: Reputation: 32
AWK is weird with Variables

Anything you put in " " will be taken literally so

"$EMAIL" is actually being sent as $EMAIL instead of variable value and since awk is local with variables anything defined outside of the awk will not be recognized.

So in order to make this work you need to make the variable appear in what you grep:

I'm not familar enough with mailq to be able to help with awk if you could post a mailq line I probably could help a bit more. What does a line look like?

Sub personal info - all i need is format.

Last edited by kbscores; 06-18-2012 at 12:54 PM.
Old 06-18-2012, 01:08 PM   #3
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,120

Rep: Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140
if you already use awk try to use only one awk script instead of this chain of tail|grep|awk|tr.
Also would be nice to copy the output of mailq before processing and describe the result you want to get

Happy with solution ... mark as SOLVED
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
Old 06-18-2012, 01:17 PM   #4
LQ Newbie
Registered: Jun 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
I was able to make this work with "'$EMAIL'" (pure trial and error perseverance!)

Decided to have it ask you for the email address first. Here's what my functional script currently looks like:

echo -n "What is the email address? "
read -e EMAIL
mailq | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if ($7 == "'$EMAIL'") print $1 } ' | tr -d '*!' | postsuper -d -

This was created because we get spam outbreaks from time to time that fill the queue to the brim. Previously I had to execute the script manually and paste in the sender's reply-to address. This automates the process and reduces 3am fat fingering.

Thanks for the replies.


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
Need help with script writing: Storing cmd in variable, print variable, then exe cmds Arodef Programming 3 01-17-2012 01:26 AM
Script to copy specific directory based on variable to folder with that variable name fluxburn Programming 7 01-07-2010 08:59 PM
Problem with bash script - variable name within variable name steven.c.banks Linux - Newbie 3 03-10-2009 04:08 AM
Help: removing a variable substring from a string variable in sh script gnparsons Programming 2 06-04-2008 06:21 PM
setting a variable variable in a script... this works, but could it be more elegant? pwc101 Programming 3 08-18-2006 12:23 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:23 PM.

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