Link to home
Start Free TrialLog in
Avatar of sunhux
sunhux

asked on

Unix Shell script to prompt for an email address & insert it into 3rd line of a file

A Shell script is preferred over a Perl script for this request.

From time to time I need to block a spam, so instead of going to the directory
& edit a file & save it, I would like to automate this a bit with a Shell script.
This script's requirements:

a) cd /folderA

b) make a backup of current file ie
       cp -p access_sender access_sender.ddmmyyyy  
    where ddmmyyyy is the day, month, year (in digits)

c) prompt for the offending/spam email address I wish to block & store into a variable ie
       Pls enter spam address to block: <this is where I'll key in the email address, eg: aa@bb.com>

d) use awk or nawk or sed to insert the email address entered into
     line 3 of access_sender plus a TAB followed by the text  REJECT.  Eg:
       aa@bb.com      REJECT
     Note: Lines 1 & 2 will stay while the former line 3, 4 onwards will get pushed down 1 line

e) then execute the command "postfix reload"

   
SOLUTION
Avatar of wilmaflintstone
wilmaflintstone

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sunhux
sunhux

ASKER


Thanks chaps.

KeremE's script meet my requirements exactly.

I'll be submitting another post to Shell Scripting zone for a similar request or in a way an additional
enhancement to KeremE's script, so look out for it
You're welcome.