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"
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're welcome.
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