首页 | 邮件资讯 | 技术教程 | 解决方案 | 产品评测 | 邮件人才 | 邮件博客 | 邮件系统论坛 | 软件下载 | 邮件周刊 | 热点专题 | 工具
网络技术 | 操作系统 | 邮件系统 | 客户端 | 电子邮箱 | 反垃圾邮件 | 邮件安全 | 邮件营销 | 移动电邮 | 邮件软件下载 | 电子书下载

邮件服务器

技术前沿 | Qmail | IMail | MDaemon | Exchange | Domino | 其它 | Foxmail | James | Kerio | JavaMail | WinMail | Sendmail | Postfix | Winwebmail | Merak | CMailServer | 邮件与开发 | 金笛 |
首页 > 邮件服务器 > Postfix > 邮件帐号管理的shell script > 正文

邮件帐号管理的shell script

出处:blog.chinaunix.net 作者:漠北色狼 时间:2007-3-14 19:25:25
这个shell script是用来操作我的邮服帐号的,现在提供了查看,删除,修改,更新等基本功能。还没有最终完成,比如在部分出错处理时,采用简单忽略的处理方式,数据库的备份和恢复也没加进去呢,删除帐号时也没有提供是否要删除邮件内容的的选择,现在是不删,测试嘛,省的删了又建,麻烦,嘻嘻!有时间再来改吧!

真要酬谢我的兄弟p4s2wd啊,前些日子,他发了个在线音乐的网址给我,让我听某个电台,我的firefox无法正常显示,我生气就换成win2000了,我的shell稿子,就这么一生气忘了备份了,呵呵呵,装完系统,补丁更新完毕,重启,啊,win2000起不来了,我晕倒!算了,还是换回来吧!于是又用debian sarge做桌面!这时候才想起来,我的那个脚本没有备份!还好我运气虽然差,还没差到家,呵呵,我记得给我兄弟p4s2wd发过一次,请他斧正的,于是让他又发回给我!他没删噢!哈哈

#!/bin/sh
#menu
#Main Menu Script
#set -x
#ignore CTRL-C and QUIT interrupts
trap "" 2 3 15
MYDATE=`date +%d/%m/%Y`
THIS_HOST=`hostname -s`

USER=`whoami`

#User level file
USER_LEVELS=priv.user

#hold file
HOLD1=hold1.$$

#select1_result file
SELECT1_RESULT=select1_result.$$

#seleclt_op file
SELECT1_OP=select1_op.$$
#Colour function
colour()
{
#format is background;foregroundm
case $1 in
black_green)
echo ""
;;
black_yellow)
echo ""
;;
black_white)
echo ""
;;
black_cyan)
echo ""
;;
red_yellow)
echo ""
;;
esac
}

#Just read a single key please
#get_char()
#{
#get_char
#Save current stty settings
#SAVEDSTTY=`stty -g`
#stty cbreak
#dd if=/dev/tty bs=1 count=1 2> /dev/null
#stty -cbreak
#stty $SAVEDSTTY
#}

#Turn the cursor on or off
cursor()
{
#cursor
#turn cursor on/off

_OPT=$1
case $_OPT in
on) echo "[?25h"
;;
off) echo "[?25l"
;;
*) return 1
;;
esac
}

#check what privilege level the user has
restrict()
{
colour red_yellow
echo -e -n " 07Sorry you are not authorised to use this function"
colour black_green
}

user_level()
{
#user_level
#read in the priv.user file
while read LINE
do
case $LINE in
#ignore comments
#*)
;;
*)
echo $LINE >> $HOLD1
;;
esac
done < $USER_LEVELS

FOUND=false
while read MENU_USER PRIV
do
if [ "$MENU_USER" = "$USER" ]
then
FOUND=true
case $PRIV in
yes|YES)
return 0
;;
no|NO)
return 1
;;
esac
else
#no match found read next record
continue
fi
done <$HOLD1
if [ "$FOUND" = "false" ]
then
echo "Soryy $User you have not been authorised to use this menu"
exit 1
fi
}

#called when user selects quit
my_exit()
{
#my_exit
#called when user selects quit!
colour black_white
cursor on
rm *.$$
exit 0
}

tput init
#display their user levels on the screen
if user_level; then
ACCESS="Access Mode is High"
else
ACCESS="Access Mode is Normal"
fi


my_select1()
{
clear
colour black_green
cat <
----------------------------------------------------------------------------
EOF
colour black_cyan
echo "use postfix;select username,name from mailbox;">$SELECT1_OP
$MYSQL -uroot<$SELECT1_OP >>$SELECT1_RESULT
rm $SELECT1_OP
#SERIAL=0
#MYPAUSE=0
#while read MAILNAME NAME
#do
# SERIAL=`expr $SERIAL + 1`
# MYPAUSE=`expr $MYPAUSE + 1`
# if [ $MYPAUSE -eq 5 ];then
# echo "Press any key continue..."
# MYPAUSE=0
# read DUMMY
# fi
# echo -e -n "$MAILNAME $NAME "
#done<$SELECT1_RESULT
more -5 -d $SELECT1_RESULT
colour black_cyan
echo -e -n " total:$SERIAL"
colour black_green
cat <
-----------------------------------------------------------------------------
EOF
colour black_cyan
rm $SELECT1_RESULT
}

my_select1_result()
{
while :
do
colour black_green
cat <
$ACCESS
-----------------------------------------------------------------------------
User:$USER Host:$THIS_HOST Date:$MYDATE
-----------------------------------------------------------------------------
1.Detail mailbox
2.Display mailbox again
3.Return
H.Help
Q.Exit
-----------------------------------------------------------------------------
EOF
colour black_cyan
echo -e -n " Your Choice [1,2,3,H,Q >"
read MY_SELECT
case $MY_SELECT in
1)
echo -e -n "Please input you are going to detail mailbox:"
read MAILNAME
echo "use postfix; select username as 'mailbox',password as 'password',name as 'true name', maildir as 'maildir',quota as 'quota',domain as 'domain',created as 'created time',modified as 'modified time',active as 'active' from mailbox where username LIKE '$MAILNAME%' G;">$SELECT1_OP
clear
$MYSQL -uroot<$SELECT1_OP
rm $SELECT1_OP
;;
2)
my_select1
;;
3)
break
;;
q|Q)
my_exit
;;
*)
;;
esac
done
}


my_delete1()
{
while :
do
colour black_green
cat <
$ACCESS
-----------------------------------------------------------------------------
User:$USER Host:$THIS_HOST Date:$MYDATE
-----------------------------------------------------------------------------
1.Delete mailbox
2.Display mailbox again
3.Return
H.Help
Q.Exit
-----------------------------------------------------------------------------
EOF
colour black_cyan
echo -e -n " Your Choice [1,2,3,H,Q >"
read MY_SELECT
case $MY_SELECT in
1)
echo -e -n "Please input you are going to delete mailbox:"
read MAILNAME
echo "use postfix;select * from mailbox where username='$MAILNAME';">$SELECT1_OP
MYSELECT=`$MYSQL -uroot<$SELECT1_OP`
if [ -z $MYSELECT ]; then
echo "input failed:"
break
else
{
echo "use postfix;delete from mailbox where username='$MAILNAME';">$SELECT1_OP
echo "delete $MAILNAME[Y/N]"
read MYDELETE
if [ "$MYDELETE" == "Y" -o $MYDELETE == "y" ];then
$MYSQL -uroot<$SELECT1_OP
echo "delete successful"
break
else
echo "delete failed"
fi
}
fi
;;
2)
my_select1
;;
3)
break
;;
H|h)
echo "this is a help file"
;;
Q|q)
my_exit
;;
esac
done
}

my_update1()
{
while :
do
colour black_green
cat <
$ACCESS
------------------------------------------------------------------------------
User:$USER Host:$THIS_HOST Date:$MYDATE
------------------------------------------------------------------------------
1.Update mailbox
2.Display mailbox again
R.Return
H.Help
Q.Exit
------------------------------------------------------------------------------
EOF
colour black_cyan
echo -e -n " Your Choice[1,2,R,H,Q]:"
read MY_SELECT
case $MY_SELECT in
1)
while :
do
echo -e -n "Please input you are going to modify mailbox:"
read MAILNAME
[ -z "$MAILNAME" ] || break
done
echo "use postfix;select username from mailbox where username='$MAILNAME'">$SELECT1_OP
MYSELECT=`$MYSQL -uroot<$SELECT1_OP`
if [ -z "$MYSELECT" ];then
echo "update failed"
else
while :
do
echo -e -n "Please input password:"
read MYPASSWD
echo -e -n "Please input password again:"
read REMYPASSWD
if [ $MYPASSWD = $REMYPASSWD ];then
break
else
echo "password no match"
fi
done

echo -e -n "Please input user:"
read MYNAME
echo -e -n "active[y/n]"
read MYACTIVE
case $MYACTIVE in
Y|y)
MYACTIVE="1"
;;
N|n)
MYACTIVE="0"
;;
esac
MYMAILDIR="$MAILNAME/"
echo "modify[y/n]"
read MYSELECT
case $MYSELECT in
y|Y)
MYDATE=`date "+%Y-%m-%d %H:%M:%S"`
echo "use postfix;update mailbox set password='$MYPASSWD',name='$MYNAME',quota=0,modified='$MYDATE',active='$MYACTIVE' where username='$MAILNAME'">$SELECT1_OP
$MYSQL -uroot <$SELECT1_OP
echo "update successful"
;;

n|N)
echo "update failed"
;;
esac
fi

;;
2)
my_select1
;;
R|r)
break
;;
Q|q)
my_exit
;;
*)
;;
esac
done
}

my_new1()
{
while :
do
echo -e -n "Please input new mailbox:"
read MAILNAME
[ -z "$MAILNAME" ] || break
done
echo "use postfix;select username from mailbox where username='$MAILNAME';">$SELECT1_OP
MYSELECT=`$MYSQL -uroot<$SELECT1_OP`
if [ -n "$MYSELECT" ];then
echo "create mailbox failed"
else
while :
do
echo -e -n "Please input password:"
read MYPASSWD
echo -e -n "Please input password again:"
read REMYPASSWD
if [ $MYPASSWD = $REMYPASSWD ];then
break
else
echo "password no match"
fi
done
echo -e -n "Please input user:"
read MYNAME
echo -e -n "active[y/n]"
read MYACTIVE
case $MYACTIVE in
Y|y)
MYACTIVE="1"
;;
N|n)
MYACTIVE="0"
;;
esac
MYMAILDIR="$MAILNAME/"
echo "modify[y/n]"
read MYSELECT
case $MYSELECT in
y|Y)
MYDATE=`date "+%Y-%m-%d %H:%M:%S"`
MYDOMAIN=`echo $MAILNAME|awk -F@ '{print $2}'`
echo "use postfix;insert into mailbox (username,password,name,maildir,quota,domain,created,active) valuse('$MAILNAME','$MYPASSWD','$MYNAME','$MYMAILDIR',0,'$MYDOMAIN','$MYDATE','$MYACTIVE');">$SELECT1_OP
$MYSQL -uroot <$SELECT1_OP
echo "create successful"
;;
n|N)
echo "create failse"
;;
esac
fi
}


tput init
colour black_green
while :
do
tput clear
colour black_green
cat <
$ACCESS
-----------------------------------------------------------------------------
User:$USER Host:$THIS_HOST Date:$MYDATE
-----------------------------------------------------------------------------
1.Display mailbox
2.Delete mailbox
3.Modify mailbox
4.New mailbox
H.Help
Q.Exit
-----------------------------------------------------------------------------
EOF

colour black_cyan
echo -e -n " Your Choice [1,2,3,H,Q >"
MYSQL="/opt/mysql5/bin/mysql"
[ -x $MYSQL ] || exit 0
read CHOICE
case $CHOICE in
1)
my_select1
my_select1_result
;;
2)
my_select1
my_delete1
;;
3)
my_select1
my_update1
;;
4)
my_new1
;;
H|h)
tput clear
cat <
This is a help file
EOF
;;
Q|q)
my_exit
;;
*)
echo -e " 07unknown user response"
;;
esac
echo -e -n " 07Hit the return key to continue"
read DUMMY
done

相关文章 热门文章
  • 快压技巧分享:秒传邮件超大附件
  • 不容忽视的邮件营销数据分析过程中的算法问题
  • 穿越时空的爱恋 QQ邮箱音视频及贺卡邮件
  • 入侵邻居网络发骚扰邮件 美国男子被重判入狱18年
  • 网易邮箱莫子睿:《非你莫属》招聘多过作秀
  • 如何在iPhone/iPod touch/iPad邮件应用程序Mail中使用QQ邮箱Exchange移动终端同步服务?
  • 邮件业务对Google、微软和雅虎为何如此重要?
  • 新型电子邮件服务Shortmail获75万美元种子资金
  • “发妻”揭院士候选人“包N奶”电子邮件露“奸情”
  • 刘子骏:利用QQ邮件列表 做精准的邮件营销
  • 韩媒称韩国学生电子邮件收发能力全球排第一
  • 企业邮箱与垃圾邮件的战争
  • Install and configure Postfix with Cyrus-SASL+Cyr...
  • 在FreeBSD上建立一个功能完整的邮件服务器
  • postfix 邮件病毒过滤
  • 在Fedora上建立自己的邮件服务器
  • Postfix + SpamAssassin 安裝手冊
  • Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP...
  • Postfix + Cyrus-SASL + Cyrus-IMAPD + PgSQL HOWTO
  • 在FreeBSD5.1簡單安裝Postfix+Qpopper+Openwebmail
  • 在RHEL 4 上配置全功能的Postfix 服务器
  • Postfix + Cyrus-IMAP + Cyrus-SASL + MySQL + IMP 完..
  • 我的POSTFIX安装笔记
  • Postfix电子邮局的配置步骤
  • 自由广告区
     
    最新软件下载
  • SharePoint Server 2010 部署文档
  • Exchange 2010 RTM升级至SP1 教程
  • Exchange 2010 OWA下RBAC实现的组功能...
  • Lync Server 2010 Standard Edition 标..
  • Lync Server 2010 Enterprise Edition...
  • Forefront Endpoint Protection 2010 ...
  • Lync Server 2010 Edge 服务器部署文档
  • 《Exchange 2003专家指南》
  • Mastering Hyper-V Deployment
  • Windows Server 2008 R2 Hyper-V
  • Microsoft Lync Server 2010 Unleashed
  • Windows Server 2008 R2 Unleashed
  • 今日邮件技术文章
  • 腾讯,在创新中演绎互联网“进化论”
  • 华科人 张小龙 (中国第二代程序员 QQ...
  • 微软推出新功能 提高Hotmail密码安全性
  • 快压技巧分享:秒传邮件超大附件
  • 不容忽视的邮件营销数据分析过程中的算..
  • 国内手机邮箱的现状与未来发展——访尚..
  • 易观数据:2011Q2中国手机邮箱市场收入..
  • 穿越时空的爱恋 QQ邮箱音视频及贺卡邮件
  • Hotmail新功能:“我的朋友可能被黑了”
  • 入侵邻居网络发骚扰邮件 美国男子被重..
  • 网易邮箱莫子睿:《非你莫属》招聘多过..
  • 中国电信推广189邮箱绿色账单
  • 最新专题
  • 鸟哥的Linux私房菜之Mail服务器
  • Exchange Server 2010技术专题
  • Windows 7 技术专题
  • Sendmail 邮件系统配置
  • 组建Exchange 2003邮件系统
  • Windows Server 2008 专题
  • ORF 反垃圾邮件系统
  • Exchange Server 2007 专题
  • ISA Server 2006 教程专题
  • Windows Vista 技术专题
  • “黑莓”(BlackBerry)专题
  • Apache James 专题
  • 分类导航
    邮件新闻资讯:
    IT业界 | 邮件服务器 | 邮件趣闻 | 移动电邮
    电子邮箱 | 反垃圾邮件|邮件客户端|网络安全
    行业数据 | 邮件人物 | 网站公告 | 行业法规
    网络技术:
    邮件原理 | 网络协议 | 网络管理 | 传输介质
    线路接入 | 路由接口 | 邮件存储 | 华为3Com
    CISCO技术 | 网络与服务器硬件
    操作系统:
    Windows 9X | Linux&Uinx | Windows NT
    Windows Vista | FreeBSD | 其它操作系统
    邮件服务器:
    程序与开发 | Exchange | Qmail | Postfix
    Sendmail | MDaemon | Domino | Foxmail
    KerioMail | JavaMail | Winwebmail |James
    Merak&VisNetic | CMailServer | WinMail
    金笛邮件系统 | 其它 |
    反垃圾邮件:
    综述| 客户端反垃圾邮件|服务器端反垃圾邮件
    邮件客户端软件:
    Outlook | Foxmail | DreamMail| KooMail
    The bat | 雷鸟 | Eudora |Becky! |Pegasus
    IncrediMail |其它
    电子邮箱: 个人邮箱 | 企业邮箱 |Gmail
    移动电子邮件:服务器 | 客户端 | 技术前沿
    邮件网络安全:
    软件漏洞 | 安全知识 | 病毒公告 |防火墙
    攻防技术 | 病毒查杀| ISA | 数字签名
    邮件营销:
    Email营销 | 网络营销 | 营销技巧 |营销案例
    邮件人才:招聘 | 职场 | 培训 | 指南 | 职场
    解决方案:
    邮件系统|反垃圾邮件 |安全 |移动电邮 |招标
    产品评测:
    邮件系统 |反垃圾邮件 |邮箱 |安全 |客户端
    广告联系 | 合作联系 | 关于我们 | 联系我们 | 繁體中文
    版权所有:邮件技术资讯网©2003-2010 www.5dmail.net, All Rights Reserved
    www.5Dmail.net Web Team   粤ICP备05009143号