即使是按skiddie标准,我还是一个完整的菜鸟,我正在尝试编写一个可以执行以下操作的脚本:
/^.*
/^.*
到目前为止,我已经完成了简单的部分,让脚本要求输入电子邮件地址,就像这样:
$/ REJECT
echo -e "\nPlease enter user's email address to add to Sender Access blocklist:"
我并不懒惰,只在寻找一种复制/粘贴解决方案(但我不介意),因此,如果您可以向正确的方向指点,那也将不胜感激。
谢谢。
答案 0 :(得分:0)
好吧,我深入挖掘了一点,我设法将不同的点滴拼凑在一起,形成了一个有效的脚本。到目前为止,它并不是最漂亮的野兽,但考虑到它实际上是我的第一个-我很高兴:)我将在这里完整地分享它,以防别人也需要它。
#!/bin/bash
## USERMAIL is a mail address to be added to the blocklist
COUNTER=0
while [ $COUNTER -lt 1 ]; do
clear ## clears the screen
echo -e "\nPlease enter user's email address to add to Sender Access blocklist (to minimize errors, please copy the email address):"
echo ""
read -p 'Email:' USERMAIL ## this is where user provides an email
if
grep $USERMAIL /etc/postfix/sender_access_regexp;
then echo -e "\nUser already exists on this list." ## this checks if there is such an address on the list already
else
echo /^.*$USERMAIL$/ REJECT >> /etc/postfix/sender_access_regexp ## the bits and pieces surrounding $USERMAIL are all part of regex
echo -e "\nUser $USERMAIL added to blocklist."
echo ""
fi
echo""
read -p "Would you like to add another addres to Sender Access blocklist? (y/n)" -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]
then let COUNTER=COUNTER+0
echo ""
else let COUNTER=COUNTER+1
echo ""
fi
done
postmap /etc/postfix/sender_access_regexp
postfix reload
echo ""
read -n 1 -s -r -p "All done, press any key to continue"
echo ""
就这样。所有这些 echo ""
都在那儿,因为我不知道如何添加空行:shrug:
P.S。如果 permission denied
的所有者和您的脚本不是同一用户,您可能会得到 /etc/postifx/sender_access_regexp
。
P.P.S。仍然欢迎所有有关简化此脚本的建议!